[英](Python 3.4 Tkinter) Frame issue
When I run this code: 当我运行此代码时:
from tkinter import *
root = Tk()
fr = Frame(root, width=50, height=50).pack()
b = Button(fr, text='Click').pack()
root.mainloop()
button 'b' is outside the frame 'fr', acting as if i wrote root
instead of fr
in b = Button(fr, ...
. 按钮'b'在框架'fr'之外,就像我在b = Button(fr, ...
写root
而不是fr
。
You should execute pack on the object returned from Frame and Button. 您应该对从Frame和Button返回的对象执行pack。
fr = Frame(root, width=50, height=50)
fr.pack()
b = Button(fr, text='Click')
b.pack()
Otherwise, your fr and b are None, ie they take values returned by pack()
which is None. 否则,您的fr和b为None,即它们采用pack()
返回的值为None。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.