我想做个登录表。 如果我在表单中添加一个按钮,当哪里出现一个很大的空格时。 我尝试了grid_columnfigure的权重=1,但是它只设置了一点点的x坐标(比如self.NewProfilePasswordEntry) 我的代码:
from tkinter import *
from tkinter import ttk
class App:
def CreateProfileDataInput(self):
Root = Tk()
Root.resizable(width=FALSE, height=FALSE)
Root.geometry("450x500")
NewProfilePasswordRepeatLabel = Label(Root, text="Passwort wiederholen", font="Tahoma 13").grid(row=3, column=0, padx=(10, 20), pady=(20, 0), sticky=W)
self.NewProfilePasswordRepeatEntry = ttk.Entry(Root, width=35, show="*").grid(row=3, column=1, pady=(20, 0))
self.CreateProfileButton = Button(Root, text="Profil erstellen", width=55, height=2, relief="flat", borderwidth=1, bg="#30b1e8", command=lambda:self.CreateProfile()).grid(row=4, column=0, pady=(25, 0))
Root.mainloop()
App().CreateProfileDataInput()
最简单的方法是按建议添加
columnspan=2
,即here。发生上述情况的原因是网格列的行长度是根据列中最长的列计算的,在上面的例子中是Button
。当您设置columnspan=2
时,它会对其进行调整,使小部件占用两列而不是一列。在另外,请注意,我冒昧地将布局调用与小部件创建调用分开,如果不进行分离,则变量都是
None
,这在以后可能会有问题。在相关问题 更多 >
编程相关推荐