繁体   English   中英

使用tkinter列表框时发生令人困惑的错误

[英]confusing error occured when using tkinter listbox

使用self时遇到了一个非常令人困惑的错误:

我在这里用两个不同的类使用tkinter创建了两个页面。 一页显示雇员信息,另一页允许用户将数据添加到主页(显示数据的窗口)上的列表框中。 我试图将信息添加到列表框中,但出现错误'NewEmployee' object has no attribute 'listbox'

在下面您可以看到我清楚地使用了自我。 对于我所做的列表框,错误显示了一个不同的类,列表框不在其中?

class MainPageGUI:
    def __init__(self, master):

        self.master = master
        self.master.title("Jans Corp")
        self.master.configure(background='lightgrey')
        self.master.geometry("1200x800")

        self.listbox = tk.Listbox(self.master,width=150, height=35)
        self.listbox.place(x=150, y = 130)

        @staticmethod
        def DisplayData(self):
        a = Database(self.master)
             for data in enumerate(a.ReadData()):
             self.listbox.insert(1, data) #getting error here

允许用户使用输入框和按钮添加emplyoee数据的类。(不完整):

添加员工页面

class NewEmployee:
    def __init__(self, master): #Creating basic GUI to add employees

        self.master = master
        self.master.title("Jans Corp")
        self.master.configure(background="lightgrey")
        self.master.geometry("300x500")

我对为什么编译器说NewEmployee类在ive在MainPageGUI创建并使用self时没有“列表框”感到困惑。

如果有人想查看代码: https : //github.com/Sharjeel50/Database-System/blob/master/New%20Project1.py

任何帮助或解释将不胜感激!

如果要在DisplayData使用self.master ,请删除@staticmethod装饰器,并在__init__包括self.master = master

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM