#๐Ÿ”’ CustomTKinter not switching frames

11 messages ยท Page 1 of 1 (latest)

wicked surge
#

I made an UI using customtkinter, but I have an issue with it not changing the frame.

class MainFrame(customtkinter.CTkFrame):
    def __init__(self, master):
        super().__init__(master)

        self.grid_columnconfigure(0, weight=1)
        self.grid_rowconfigure(0, weight=1)

        self.active_users_frame = ActiveUsers(self)
        self.login_frame = Login(self)

        print("Hello from MainFrame")

    def show_frame(self, value):
        print(f"Hello From {value}")
        generate_frames(self.active_users_frame, self.login_frame, value)

class App(customtkinter.CTk):
    def __init__(self):
        super().__init__()
        self.title("PE Gear Manager")
        customtkinter.set_appearance_mode("light")

        self.grid_columnconfigure(0, weight=1)
        self.grid_rowconfigure((0, 1, 2), weight=1)

        self.main_frame = MainFrame(self)
        self.main_frame.grid(row=2, column=0, sticky="nswe")
        self.main_frame.show_frame("Active Users")

        self.line_separator = LineSeparator(self)
        self.line_separator.grid(row=1, column=0, sticky="nwe")

        self.main_menu = MenuFrame(self)
        self.main_menu.grid(row=0, column=0, padx=5, pady=(10, 0), sticky="nwe")


app = App()
app.mainloop()
ember owlBOT
#

@wicked surge

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

wicked surge
#
def generate_frames(
    active_users,
    login,
    value,
):
    print("Hello WOOORLD")

    active_users.grid_remove()
    login.grid_remove()

    if value == "Active Users":
        active_users.grid(row=0, column=0, sticky="nswe")
    elif value == "Student Login":
        login.grid(row=0, column=0, sticky="nswe")
    else:
       raise Exception("Not in the menu")
#
class MenuFrame(customtkinter.CTkFrame):
    def __init__(self, master):
        super().__init__(master)

        self.grid_columnconfigure(1, weight=1)
        self.grid_rowconfigure(0, weight=0)

        university_logo = customtkinter.CTkLabel(self, text="University Logo")
        university_logo.grid(row=0, column=0, padx=10, pady=10, sticky="w")

        menu_buttons = customtkinter.CTkSegmentedButton(
            self,
            values=[
                "Active Users",
                "Student Login",
                "Manage Equipments",
                "Manage Students",
                "Return History",
            ],
            command=lambda value: self.get_value(value),
        )
        menu_buttons.set("Active Users")
        menu_buttons.grid(row=0, column=1, padx=10, pady=10, sticky="we")

        about_button = customtkinter.CTkButton(self, text="About")
        about_button.grid(row=0, column=2, padx=10, pady=10, sticky="e")

    def get_value(self, value):
        MainFrame(self).show_frame(value)
next prism
wicked surge
#

thanks!

#

!close

ember owlBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.