Unconquerable p 2022-07-19 20:41 采纳率: 90.9%
浏览 174
已结题

Tkinter报错 can't add .!frame2 as slave of .!toplevel.!notebook

Tkinter 报错_tkinter.TclError: can't add .!frame2 as slave of .!toplevel.!notebook
这是我的程序的一部分,我想实现一个子窗口(所以不能用tkinter.Tk())
之所以用mainloop(1)是因为不想让父窗口卡死


new = tkinter.Toplevel()
img = StyleDesign.styles_icons["stylesset"]
new.wm_iconphoto(False, img)
new.geometry("600x600")
new.title("MyTitle")
new.resizable(False, False)


def all_():
    fr = tkinter.Frame()
    fr.place({
        "width": 600,
        "height": 550,
    })
    return fr


frames = {
    "form1": all_(),
}
ch = Notebook(new)
ch.add(frames["form1"], text="ONE")
ch.place({
    "x": 0,
    "y": 0,
    "width": 600,
    "height": 600,
})
new.mainloop(1)

出错部分是ch.add()行,报错内容:

_tkinter.TclError: can't add .!frame2 as slave of .!toplevel.!notebook

  • 写回答

1条回答 默认 最新

  • Unconquerable p 2022-07-20 10:48
    关注

    自己解决了:11行处改为

        fr = tkinter.Frame(master=new)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 7月28日
  • 已采纳回答 7月20日
  • 创建了问题 7月19日