所以我在 Windows (python 3.8.5) 和 Linux (python 3.8.2) 上出現(xiàn)了一個(gè)獨(dú)特的問題。當(dāng)我將一個(gè)小部件放置在某個(gè)框架中時(shí),它實(shí)際上出于某種原因放置在根目錄中。我正在使用TkinterExtensions庫。我看過這個(gè)答案,但沒有幫助。無論我做什么,我都會遇到這個(gè)問題,但僅限于一幀。我現(xiàn)在懷疑這可能是 Tkinter 庫錯(cuò)誤。編輯:這似乎只發(fā)生在 python 3.8.x 中。我在另一臺 3.7.x 的電腦上嘗試過,它按預(yù)期工作。下面是一個(gè)非常通用的示例。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 如果需要,我可以使用更廣泛的通用代碼創(chuàng)建一個(gè)存儲庫。另外,我是TkinterExtensions庫的作者。
1 回答

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