I am new OOP and UI development using tkinter. I currently have the following code:
class Snapshot_app(Tk):
def __init__(self):
Tk.__init__(self)
container = Frame(self)
container.pack(side="top", fill="both", expand=True)
self.frames = {}
for F in (StartPage, PageOne,PageTwo):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky=NSEW)
self.show_frame(StartPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
Class PageOne(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
Label(self, text="Path to files").grid(row=1,column=0)
self.fname = Entry(self)
self.fname.grid(row=1, column=1)
app.frames[PageTwo].dummy = self.fname.get()
b = Button(self,text="Open Page 2",command=lambda:app.show_frame(PageTwo)).grid(row=2,column=1)
Class PageTwo(Frame):
def __init__(self, parent, controller,dummy=None):
Frame.__init__(self, parent)
self.data = dummy
print(self.data)
app = Snapshot_app()
app.title("Snapshot Tool")
app.geometry("1200x400")
app.mainloop()
In PageTwo class, it gives me an error saying self.data=None. Which means I am unable to pass the dummy information from PageOne to PageTwo. However, if I put a button on PageTwo whose event triggers the printing of self.data, I am able to successfully get the data from PageOne. I would like to however really avoid usign the button. Any pointers and help would be much appreciated!