【问题标题】:(Python 3.4 Tkinter) Frame issue(Python 3.4 Tkinter)框架问题
【发布时间】:2014-12-03 07:36:35
【问题描述】:

当我运行这段代码时:

from tkinter import *
root = Tk()

fr = Frame(root, width=50, height=50).pack()
b = Button(fr, text='Click').pack()

root.mainloop()

按钮“b”在框架“fr”之外,就像我在b = Button(fr, ... 中写了root 而不是fr

【问题讨论】:

    标签: python python-3.x tkinter


    【解决方案1】:

    您应该对从 Frame 和 Button 返回的对象执行打包。

    fr = Frame(root, width=50, height=50)
    fr.pack()
    b = Button(fr, text='Click')
    b.pack()
    

    否则,您的 fr 和 b 为 None,即它们采用 pack() 返回的值,即 None。

    【讨论】:

      猜你喜欢
      • 2015-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-07
      相关资源
      最近更新 更多