73 lines
2.2 KiB
Python
73 lines
2.2 KiB
Python
import tkinter as tk
|
|
from tkinter import ttk
|
|
|
|
|
|
class windows(tk.Tk):
|
|
def __init__(self, *args, **kwargs):
|
|
tk.Tk.__init__(self, *args, **kwargs)
|
|
self.wm_title("Test Application")
|
|
|
|
container = tk.Frame(self, height=400, width=600)
|
|
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 (MainPage, SidePage, CompletionScreen):
|
|
frame = F(container, self)
|
|
|
|
self.frames[F] = frame
|
|
frame.grid(row=0, column=0, sticky="nsew")
|
|
|
|
self.show_frame(MainPage)
|
|
|
|
def show_frame(self, cont):
|
|
frame = self.frames[cont]
|
|
frame.tkraise()
|
|
|
|
|
|
class MainPage(tk.Frame):
|
|
def __init__(self, parent, controller):
|
|
tk.Frame.__init__(self, parent)
|
|
label = tk.Label(self, text="Main Page")
|
|
label.pack(padx=10, pady=10)
|
|
|
|
# We use the switch_window_button in order to call the show_frame() method as a lambda function
|
|
switch_window_button = tk.Button(
|
|
self,
|
|
text="Go to the Side Page",
|
|
command=lambda: controller.show_frame(SidePage),
|
|
)
|
|
switch_window_button.pack(side="bottom", fill=tk.X)
|
|
|
|
|
|
class SidePage(tk.Frame):
|
|
def __init__(self, parent, controller):
|
|
tk.Frame.__init__(self, parent)
|
|
label = tk.Label(self, text="This is the Side Page")
|
|
label.pack(padx=10, pady=10)
|
|
|
|
switch_window_button = tk.Button(
|
|
self,
|
|
text="Go to the Completion Screen",
|
|
command=lambda: controller.show_frame(CompletionScreen),
|
|
)
|
|
switch_window_button.pack(side="bottom", fill=tk.X)
|
|
|
|
|
|
class CompletionScreen(tk.Frame):
|
|
def __init__(self, parent, controller):
|
|
tk.Frame.__init__(self, parent)
|
|
label = tk.Label(self, text="Completion Screen, we did it!")
|
|
label.pack(padx=10, pady=10)
|
|
switch_window_button = ttk.Button(
|
|
self, text="Return to menu", command=lambda: controller.show_frame(MainPage)
|
|
)
|
|
switch_window_button.pack(side="bottom", fill=tk.X)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
testObj = windows()
|
|
testObj.mainloop()
|