【发布时间】:2018-02-28 00:46:37
【问题描述】:
我正在尝试在框架上为正在运行的应用程序放置一个按钮... 但是当我使用 pack 或 grid
时,框架消失from Tkinter import *
root=Tk()
width = root.winfo_screenwidth()
height = root.winfo_screenheight()
root.geometry(str(width)+'x'+str(height))
frame=Frame(root,width=500, height=500, bg='black')
but1=Button(frame,text='qwe')
but1.grid()
frame.grid()
root.mainloop()
如果我使用 place,更糟糕的是,它们都会消失...我看不到 Frame 和 Button
from Tkinter import *
root=Tk()
width = root.winfo_screenwidth()
height = root.winfo_screenheight()
root.geometry(str(width)+'x'+str(height))
frame=Frame(root,width=500, height=500, bg='black')
but1=Button(frame,text='qwe')
but1.place()
frame.place()
root.mainloop()
但是当我使用 pack_propagate(0) 时,我可以同时看到它们...
from Tkinter import *
root=Tk()
width = root.winfo_screenwidth()
height = root.winfo_screenheight()
root.geometry(str(width)+'x'+str(height))
frame=Frame(root,width=500, height=500, bg='black')
but1=Button(frame,text='qwe')
but1.pack()
frame.pack_propagate(0)
frame.pack()
root.mainloop()
我的问题是,
- pack_propagate(0) 是什么意思?
- 为什么框架在使用和不使用 pack_propagate(0) 的情况下表现异常?
- GRID 和 PLACE 的 pack_propagate(0) 的等效项是什么?
【问题讨论】:
标签: python python-3.x python-2.7 tkinter tkinter-layout