i have my tkinter gui split in different classes and want to connect them in a home screen with buttons, like Steven M. Vascellaro did here: Switch between two frames in tkinter
import tkinter.ttk as ttk
#from alexa_site_2 import Frame_alexa
from globals import Globals
from tkinter import PhotoImage
import tkinter as tk
class SampleApp(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self._frame = None
self.geometry('{}x{}'.format(1024, 600))
self.configure(bg="white")
for i in range(len(Globals.image_files)):
image_box = PhotoImage(file=Globals.image_files[i])
Globals.list_images.append(image_box)
self.switch_frame(StartPage)
def switch_frame(self, frame_class):
"""Destroys current frame and replaces it with a new one."""
new_frame = frame_class(self)
if self._frame is not None:
self._frame.destroy()
self._frame = new_frame
self._frame.place(x=110,y=0)
print("switch frame function")
class StartPage(ttk.Frame):
def __init__(self, master):
ttk.Frame.__init__(self, master)
#self.place(x=0,y=0)
ttk.Label(self, text="This is the start page").pack()
ttk.Button(self, text="Open page one",
command=lambda: master.switch_frame(PageOne)).pack()
ttk.Button(self, text="Open page two",
command=lambda: master.switch_frame(PageTwo)).pack()
ttk.Button(self, text="Open page two",
command=lambda: master.switch_frame(Frame_alexa)).pack()
class PageOne(ttk.Frame):
def __init__(self, master):
ttk.Frame.__init__(self, master)
ttk.Label(self, text="This is page one").pack(side="top", fill="x", pady=10)
ttk.Button(self, text="Return to start page",
command=lambda: master.switch_frame(StartPage)).pack()
class PageTwo(ttk.Frame):
def __init__(self, master):
ttk.Frame.__init__(self, master)
ttk.Label(self, text="This is page two").place(x=40,y=10)
ttk.Button(self, text="Return to start page",
command=lambda: master.switch_frame(StartPage)).place(x=0,y=0)
if __name__ == "__main__":
app = SampleApp()
app.mainloop()
when I try connect my own classes i get a white window as result. You can see it working in pageOne and my problem in PageTwo. I am not planning on mixing place() and pack(). I just need place() and your help please.