【发布时间】:2018-02-10 18:02:04
【问题描述】:
谁能帮我在 Tkinter 中将按钮对齐到屏幕底部。我正在关注一个 youtube 教程,他们在他们的代码中编写了我所写的内容,但它将按钮与底部对齐。我在 mac 上使用 python 3.7
from tkinter import *
root = Tk() #makes a blank popup, under the variable name 'root'
topFrame = Frame(root)
topFrame.pack()
bottomFrame = Frame(root)
bottomFrame.pack(side=BOTTOM)
button1 = Button(topFrame, text='Button 1', fg='red')
button2 = Button(topFrame, text='Button 2', fg='blue')
button3 = Button(topFrame, text='Button 3', fg='green')
button4 = Button(topFrame, text='Button 4', fg='pink')
button1.pack(side=LEFT)
button2.pack(side=LEFT)
button3.pack(side=LEFT)
button4.pack(side=BOTTOM)
root.mainloop() #loops the program forever until its closed
【问题讨论】:
-
您期望的结果是什么?我得到四个按钮水平对齐,从左到右。你想让它们垂直对齐吗?
-
底部的按钮应该在
bottomFrame,还是应该在bottomFrame的上方或下方?