【发布时间】:2019-10-31 23:03:57
【问题描述】:
我在 Python2 中使用 Tkinter 创建表单的 UI,其中 IDE 是 PyCharm。
以下是参考代码:-
from Tkinter import *;
root = Tk()
root.geometry("400x100")
#adding the header label of the tool.
myheaderTitle = Label(root,text="myForm",bg="lime green",font="Calibri 16 bold",width="400")
myheaderTitle.pack()
button_1 = Button(root,text="Select File")
button_1.grid(row=0,column=0)
root.mainloop()
我成功运行了上面的代码,但是每当我添加以下两行代码时,表单是不可见的。
button_1 = Button(root,text="Select File")
button_1.grid(row=0,column=0)
这些行可能有什么问题?
【问题讨论】:
-
不能在同一个容器中混合 grid() 和 pack()。
-
如何让网格占据全部空间
-
@BBRK 要使 grid 占据“全部空间”,您需要在容器上使用
rowconfigure和columnconfigure。检查这个link
标签: tkinter pycharm python-2.x