Search code examples
pythontkinter

Tkinter - How can i have a Sub-GUI inside a GUI that changes using buttons


I have made the Main_GUI and Sub-GUI's separately using Tkinter, My Question is that what can i do to combine them all together.

Here's the design for the layers hierarchy : https://i.sstatic.net/vMCIx.jpg


Solution

  • I created a sidebar dashboard like interface using Toplevel and Frame. Tab switching is implemented by placing the new window over the canvas and removing all other windows in the destined viewport.

    Here's a snippet of how I implemented the handle_tab_switch method:

    # Method for handling tab switching based on button presses
    def handle_tab_switch(self, caller, name):
        """
        This method handles button press events for switching tabs and updating the sidebar indicator.
        - self: The parent window
        - caller: The button that triggered the event
        - name: The name of the tab to switch to
        """
    
        # Hide all screens
        for window in self.windows.values():
            window.place_forget()
    
        # Show the selected screen
        self.current_window = self.windows.get(name)
        if self.current_window:
            self.current_window.place(x=230, y=72, width=675.0, height=405.0)
        else:
            raise ValueError(f"Window {name} does not exist.")
    
    

    here's some resources from previous comments above :