0

I want to make a simple app that switches windows whenever I pressed a button, the project was based on this answer, it worked very well using this code, However, when I tried to use place as well as other modifications.

The app stopped switching windows and it shows both canvases in the same window The App shows no buttons at all just a blank screen, Here is the code. Anyone came across something like this!?

import tkinter as tk
import tkinter.ttk as ttk


class App(tk.Tk):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.container = tk.Frame(self)
        self.container.pack(side="top", fill="both", expand=True)
        self.container.grid_rowconfigure(0, weight=1)
        self.container.grid_columnconfigure(0, weight=1)
        self.frames = {}
        for F,name in zip([page1, page2],
                       ["page1", "page2"]):
            frame = F(parent=self.container, controller=self)
            self.frames[name] = frame
            frame.grid(row=0, column=0, sticky="nsew")
            self.pack_propagate(False)

        self.show_frame("page1")

    def show_frame(self, cont):
        frame = self.frames[cont]
        frame.tkraise()


class page1(tk.Frame):
    def __init__(self, parent, controller):
        super().__init__(parent)
        self.controller = controller


        f = tk.Frame(self)
        f.place(in_=self, anchor='c', relx=.5, rely=.5)
        C1=tk.LabelFrame(f,text=' TEST PAGE 1! ',font=('Arial',13,'bold'), bg="blue")
        C1.place(relheight=.2, relwidth=.9)
        C=tk.Frame(C1,height=60,width=40)
        C.grid(row=0,column=0,columnspan=3)

        button1=tk.Button(C,text="page2"
                            ,command=lambda: controller.show_frame("page2"))
        button1.place(width=400,height=70)

class page2(tk.Frame):
    def __init__(self, parent, controller):
        super().__init__(parent)
        self.controller = controller

        f = tk.Frame(self)
        f.place(in_=self, anchor='c', relx=.5, rely=.5)
        C1=tk.LabelFrame(f,text=' TEST PAGE 2! ',font=('Arial',13,'bold'), bg="blue")
        C1.place(relheight=.2, relwidth=.9)
        C=tk.Frame(C1,height=60,width=40)
        C.grid(row=1,column=1,columnspan=3)

        button1=tk.Button(C,text="page1"
                            ,command=lambda: controller.show_frame("page1"))
        button1.place(width=200,height=70)

if __name__ == "__main__":
    app = App()
    app.geometry("1200x720+0+0")
    app.resizable(False, False)
    app.mainloop()

0 Answers0