Navigation: Home and Page Back

Obviously purpose those two button is very easy to guess. However, how does it look from the technical side?

Home

Function:

def navigate_to(self, new_screen_func):
    self.navigation_stack.append(new_screen_func)
    new_screen_func()

Definition:

self.home_button = customtkinter.CTkButton(
    self.bottom_frame,
    text="Home",
    command=lambda: self.navigate_to(self.show_home_screen)
)

Page Back

Function:

def go_back(self):
    if len(self.navigation_stack) > 1:
        self.navigation_stack.pop()
        previous_screen_func = self.navigation_stack[-1]
        previous_screen_func()
    else:
        self.show_message("No previous screen to go back to.", "Navigation")

Definition:

self.back_button = customtkinter.CTkButton(
    self.bottom_frame,
    text="Page Back",
    command=self.go_back
)

Last updated