这里有一个快速简单的方法让你的按钮坐在你的程序底部。在
首先将enter_button和{}移到根窗口。这里不需要框架。在
然后添加root.rowconfigure(),并对按钮所在的行应用权重1。使用权重配置行可以使该行与其所在的框架或窗口展开和收缩。在本例中,我们将按钮放在root中,以便配置root。你可以对一个框架做同样的事情,但这只是添加了另一个层,不需要这样简单的事情。在
这里有一段代码你可以在你的程序中替换,结果应该是你要找的。注意,我把按钮并排放置,但是你可以用同样的方法实现从上到下的操作。在
编辑:
我忘了加columnspan部分。您还需要添加其他框架的一列,这样就可以在并排时将按钮放在居中位置。columnspan用于告诉程序小部件将占用多少列。行也可以这样做。在top_frame.grid(row = 0, column = 0, columnspan = 2)
bottom_frame.grid(row = 1, column = 0, columnspan = 2)
root.rowconfigure(2, weight = 1)
#enter_button
enter_button = Button(root, text="Enter", bg='blue', fg='white')
enter_button.config(height = 2, width = 15)
enter_button.grid(row = 2, column=0, sticky = 'se')
#quit_button
quit_button = Button(root, text="Quit", bg="blue", fg="white")
quit_button.config(height = 2, width = 15)
quit_button.grid(row = 2, column=1, sticky = 'sw')
如果您想让enter按钮位于quit按钮的顶部,那么可以执行以下操作。在
^{pr2}$
如果您只是想在输入字段和按钮之间留出一点空间,您可以使用间隔标签。像这样:#empty row spacers
spacer1 = Label(bottom_frame, text = "")
spacer1.grid(row = 3)
spacer2= Label(bottom_frame, text = "")
spacer2.grid(row = 4)
#enter_button
enter_button = Button(bottom_frame, text="Enter", bg='blue', fg='white')
enter_button.config(height = 2, width = 15)
enter_button.grid(row = 5, column=1)
#quit_button
quit_button = Button(bottom_frame, text="Quit", bg="blue", fg="white")
quit_button.config(height = 2, width = 15)
quit_button.grid(row = 6, column=1)