亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Tkinter:將小部件放置在框架中實際上是將其放置在根目錄中

Tkinter:將小部件放置在框架中實際上是將其放置在根目錄中

翻閱古今 2023-09-05 20:28:16
所以我在 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所以我不知道為什么它會導致問題,但它確實發生了。



查看完整回答
反對 回復 2023-09-05
  • 1 回答
  • 0 關注
  • 105 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號