“Method”对象不是iterab

2024-10-08 18:22:24 发布

您现在位置:Python中文网/ 问答频道 /正文

尝试在tkinter GUI上显示数据库数据时当前收到错误。{但是我不知道怎么去修正错误。在

以下是我返回所有信息的课程:

class Database:
    def __init__(self, master):
        self.master = master

        self.conn = sqlite3.connect(':memory:')
        self.c = self.conn.cursor()

        self.c.execute("""CREATE TABLE Employees (
                        FirstName text,
                        Surname text,
                        Age Integer,
                        Postcode VARCHAR,
                        Wage Integer,
                        Email VARCHAR,
                        Hours Integer
                        )""") #Creation of Database

        self.conn.commit()

        self.addEmployees() # running the function, need to fix this, Only run when "add employee" button is pressed!


    def ReadData(self):
        self.c.execute("SELECT * FROM Employees")
        return self.c.fetchall() # this reads and returns all the data.

    def addEmployees(self): # This function adds all the info the users have put into the entry in new EmployeeEmail

        self.c.execute("INSERT INTO Employees VALUES (:FirstName, :Surname, :Age, :Postcode, :Wage, :Email, :Hours)",
                     {'FirstName':"Sharjeel" , 'Surname':"Jan" , 'Age':"21" ,
                     'Postcode':"aa" , 'Wage':"1220000" , 'Email':"aa" , 'Hours':"230"})

        self.conn.commit()

相当简单,这里是我尝试在按下按钮时实际显示数据的地方:

^{pr2}$

Tags: theselfmasterexecuteageemaildefinteger
1条回答
网友
1楼 · 发布于 2024-10-08 18:22:24

您必须调用ReadData方法:

# ReadData is a method, so call it:
self.ReturnedData = getattr(self.TheData, 'ReadData')()  # note the extra '()'
# Or, even more obviously, as pointed out in the comments
# self.ReturnedData = self.TheData.ReadData()
for data in enumerate(self.ReturnedData):  # I think this line threw the error

相关问题 更多 >

    热门问题