簡體   English   中英

Tkinter window 不顯示小部件

[英]Tkinter window not displaying widgets

  1. 此代碼未顯示主 window 中的任何小部件。 有什么解決辦法嗎?

  2. 有沒有辦法在一個模塊中創建多個頂級 windows? 目前,我正在為每個頂層 window 創建新的 python 模塊。

  3. 另外,在創建一個新的頂級 window 之后,我們是使用 mainloop 還是 update 或 update_ideltasks?

謝謝

 class MainWindowWidgets(ttk.Frame): def __int__(self, container): super().__init__(container) create_frame = ttk.LabelFrame(container, text='New Frame') create_frame.grid(row=0, column=0) create_btn = ttk.Button(create_frame, text='New Button') create_btn.grid(row=0, column=0) class App(tk.Tk): def __init__(self): super().__init__() self.title('My App') self.geometry('1000x500') self.resizable(False, False) main_window_widgets = MainWindowWidgets(self) main_window_widgets.pack() # This function is called from login window if login is successful and login window is destroyed def open_main_window(): app = App() app.mainloop()

您的MainWindowWidgets class 中有兩個問題:

  • __int__(...)應該是__init__(...)
  • 應該使用self而不是container作為create_frame的父級
class MainWindowWidgets(ttk.Frame): # __int__ should be __init__ instead #def __int__(self, container): def __init__(self, container): super().__init__(container) # use self instead of container as the parent #create_frame = ttk.LabelFrame(container, text='New Frame') create_frame = ttk.LabelFrame(self, text='New Frame') create_frame.grid(row=0, column=0) create_btn = ttk.Button(create_frame, text='New Button') create_btn.grid(row=0, column=0)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM