YouKnowMe
YouKnowMe

Reputation: 45

confusing error occured when using tkinter listbox

I've encountered a really confusing error when using self:

Here ive created two pages using tkinter with two different classes. One page displays employee info and the other allows users to add data into a listbox made on the main page(the window that displays data). Im trying to add info into the listbox but got an error 'NewEmployee' object has no attribute 'listbox'.

Below you can see i am clearly using self. for the listbox i have made yet the error shows a different the class the listbox is not within???

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

Class that lets users add emplyoee data using entry boxes and button.(not complete):

Add Employee page

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")

I am confused as to why the complier says NewEmployee class has no "listbox" when ive created it in MainPageGUI and also used self.

if anyone would like to view the code: https://github.com/Sharjeel50/Database-System/blob/master/New%20Project1.py

Any help or explanation would be very much appreciated!

Upvotes: 0

Views: 28

Answers (1)

user1532172
user1532172

Reputation:

If you'd like to use self.master in DisplayData, remove the @staticmethod decorator, and include self.master = master in __init__.

Upvotes: 1

Related Questions