我已经使用 Tkinter 分别制作了 Main_GUI 和 Sub-GUI,我的问题是我该怎么做才能将它们组合在一起。
这是层层次结构的设计: https://i.sstatic.net/vMCIx.jpg
我能够使用 tkinter 制作类似仪表板的界面,为此我使用了 tkinter 的 TopLevel 和 Frame。通过使用 place() 方法将新窗口放置在画布上并使用 tkraise() 将其提升到前面来实现切换。
这里是我如何实现handle_tab_switch的片段
# Method for handling tab switching based on button presses
def handle_tab_switch(self, caller, name):
"""
This method is used to handle button press events from the main window,
mainly responsible for changing the screens and sidebar indicator.
- self : i.e the parent
- caller: can be parent or from child frames
"""
# Place the sidebar on respective button
self.sidebar_indicator.place(x=0, y=caller.winfo_y())
# Hide all screens
for window in self.windows.values():
window.place_forget()
# Set current Window
self.current_window = self.windows.get(name)
# Show the screen of the button pressed
if self.current_window is not None:
self.current_window.place(x=230, y=72, width=675.0, height=405.0)
else:
raise ValueError(f"Window {name} does not exist.")
# Handle label change
self.current_name = self.windows.get(name)._name.split("!")[-1].capitalize()
self.canvas.itemconfigure(self.page_indicator, text=self.current_name)