所以我在 Windows (python 3.8.5) 和 Linux (python 3.8.2) 上出現了一個獨特的問題。當我將一個小部件放置在某個框架中時,它實際上出于某種原因放置在根目錄中。我正在使用TkinterExtensions庫。我看過這個答案,但沒有幫助。無論我做什么,我都會遇到這個問題,但僅限于一幀。我現在懷疑這可能是 Tkinter 庫錯誤。編輯:這似乎只發生在 python 3.8.x 中。我在另一臺 3.7.x 的電腦上嘗試過,它按預期工作。下面是一個非常通用的示例。from TkinterExtensions import *class Root(tk.Tk): # sets up Tkinter and creates the other windows and places them accordingly. def __init__(self): super().__init__() self.w1 = Window1(root=self).place(relx=0.0, rely=0.0, relheight=1.0, relwidth=1.0) self.w2 = Window2(root=self).place(relx=0.0, rely=0.0, relheight=1.0, relwidth=1.0) self.w3 = Window3(root=self).place(relx=0.0, rely=0.0, relheight=1.0, relwidth=1.0) self.w1.hide() self.w2.hide() self.w3.hide()class Window1(TkinterFrame): # ... anything needed for this frame # This is the frame that's causing the issue. # Despite the same code on all three windows, # this one puts any widgets into root instead of as a child of this frame. def __init__(self, root) super().__init__(root) self.button = TkinterButton(master=self, Text="button").place(relx=0.0, rely=0.0, relheight=1.0, relwidth=1.0) class Window2(TkinterFrame): # ... anything needed for this frame # this frame works fine class Window3(TkinterFrame): # ... anything needed for this frame # this frame works fine 如果需要,我可以使用更廣泛的通用代碼創建一個存儲庫。另外,我是TkinterExtensions庫的作者。
1 回答

人到中年有點甜
TA貢獻1895條經驗 獲得超7個贊
在這個特定的框架中,我定義了len方法。一旦重命名,布局管理器以及放置在其中的任何小部件就會按預期工作。Tkinter.Frame 類沒有定義len所以我不知道為什么它會導致問題,但它確實發生了。
添加回答
舉報
0/150
提交
取消