我正在创建一个GUI,其中我有一个TextBox
和几个Button
s。使用Tkinter的Python GUI - 小部件定位不正确
问题是,布局似乎是混乱的。当我增加行数以便我能够很好地分隔空间时,它没有任何区别。我不确定我犯了什么错误。
代码:
from Tkinter import *
from tkFileDialog import *
gui = Tk() #create an object
gui.title("xyz")
gui.geometry("900x300")
GuiLabel1 = Label(gui,text="hi everyone!!!!!!")
GuiLabel1.grid(row=0, column=0)
GuiLabel2 = Label(gui,text="File")
GuiLabel2.grid(row=1, column=0)
bar=Entry(gui)
bar.grid(row=1, column=1)
button1= Button(gui, text="Browse")
button1.grid(row=1, column=2)
button2= Button(gui, text="Process")
button2.grid(row=2, column=2)
button3= Button(gui, text="ABC")
button3.grid(row=3, column=0)
button4= Button(gui, text="ABC")
button4.grid(row=3, column=1)
button5= Button(gui, text="ABC")
button5.grid(row=3, column=2)
button6= Button(gui, text="ABC")
button6.grid(row=3, column=3)
button7= Button(gui, text="ABC")
button7.grid(row=3, column=4)
gui.mainloop()
请参见下面的图像的图形用户界面的截图:
究竟做*“炒” *是什么意思?该输出看起来很像我期望的。空行默认压缩到零高度;如果你想填充,添加填充。 – jonrsharpe 2014-11-03 16:07:09
从某种意义上说,这些小工具并没有按照有序的方式定位。就像第二个ABC并不完全在第一个旁边。我需要在流程按钮下方的空行。 ABC的间距不相等!!!!!!!!!! – blackfury 2014-11-03 16:35:29
然后,您需要向Tkinter提供更多关于如何布置小部件的信息(行和列大小,填充,单元格中每个小部件应该定位的位置等)。默认情况下,每行和每列都被自动调整以适合最大的窗口部件,因此第一列的宽度与'Label'的宽度相同,第二列的宽度与最大的'Button'宽度相同(第二宽度为“TextBox”一个具有最广泛的“文本”),等等......这就是“网格”所做的 - 将小部件放入网格中。 *(另外,请注意,一个感叹号通常(超过)足够。)* – jonrsharpe 2014-11-03 16:37:25