Would anyone be able to explain why "hello" is being printed when the program is run? I was expecting only the welcome_frame
to be run as that is the frame that has been raised, but that doesn't seem to be the case.
So why are all classes instantly run when I start the program, and how can I stop this from happening?
What I want is a button to be pressed within the welcome_frame
which causes everything within the edit_booking_frame
to be run.
Thank you :)
# import tkinter modules
from tkinter import *
from tkinter import ttk
# define self
class tkinterApp(Tk):
def __init__(self, *args, **kwargs):
Tk.__init__(self, *args, **kwargs)
# creating a container
container = Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
# initialising frames to an empty array
self.frames = {}
for F in (welcome_frame, edit_booking_frame):
page_name = F.__name__
frame = F(parent=container, controller=self)
self.frames[page_name] = frame
frame.grid(row = 0, column = 0, sticky = "nsew")
self.show_frame("welcome_frame")
def show_frame(self, page_name):
frame = self.frames[page_name]
frame.tkraise()
class welcome_frame(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
self.controller = controller
class edit_booking_frame(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
self.controller = controller
print("hello") ### WHY IS THIS PRINTED???
if __name__ == "__main__":
app = tkinterApp()
app.geometry("1000x800")
app.mainloop()