import tkinter as tk
from PageTwoFile import PageTwoClass
class SeaofBTCapp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
container.pack(side="top", fill="both", expand = True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, PageOne, PageTwo):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
frame.grid(row=110, column=110, sticky="nsew")
self.show_frame(StartPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
def qf(param):
print(param)
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
label = tk.Label(self, text="Start Page", font=LARGE_FONT)
label.pack(pady=10,padx=10)
button1 = tk.Button(self, text="Visit Page 1",
command=lambda: controller.show_frame(PageOne))
button1.pack()
button1 = tk.Button(self, text="Visit Page 2",
command=lambda: controller.show_frame(PageTwo))
button1.pack()
class PageOne(tk.Frame):
def __init__(self, parent,controller):
tk.Frame.__init__(self,parent)
label = tk.Label(self, text="Page One", font=LARGE_FONT)
label.pack(pady=10,padx=10)
button1 = tk.Button(self, text="Back to home",
command=lambda: controller.show_frame(StartPage))
button1.pack()
button2 = tk.Button(self, text="Two",
command=lambda: controller.show_frame(PageTwo))
button2.pack()
app = SeaofBTCapp()
app.mainloop()
In this example I have a class similiar to PageOne but in another file.
class PageTwoClass(tk.Frame):
def __init__(self, parent,controller):
tk.Frame.__init__(self,parent)
label = tk.Label(self, text="Page Two", font=LARGE_FONT)
label.pack(pady=10,padx=10)
button1 = tk.Button(self, text="Back to home",
command=lambda: controller.show_frame(StartPage))
button1.pack()
button2 = tk.Button(self, text="Page One",
command=lambda: controller.show_frame(PageOne))
button2.pack()
I can run it fine, but when I go to PageTwo I can't go back to PageOne, I get:
NameError: name 'PageOne' is not defined
I assume that is going in to PageTwoFile and does not know how to come back. How to make it read everything?
I am working on a banking system and I have another files(customer,accounts) which are imported in the main file. If I want to change frames for when they are accessed I need them to go back...