【发布时间】:2020-11-23 01:46:41
【问题描述】:
我搜索了很多关于如何使用 Tkinter 和 Python 3.8 使框架居中的信息。
我编写了一个代码,其中 4 个按钮位于一个框架中,但我不知道如何使框架在窗口中居中。我尝试了几种方法,例如grid_propagate(0)、grid(sticky="")、pack(expand=True)、...
但是没有任何效果。
我正在那里分享我最近的代码。我希望你能帮助我。
window = Tk()
frame = Frame(window)
button1 = Button(frame, text="Button 1")
button2 = Button(frame, text="Button 2")
button3 = Button(frame, text="Button 3")
button4 = Button(frame, text="Button 4")
button1.grid(row=0, column=0)
button2.grid(row=0, column=1)
button3.grid(row=1, column=0)
button4.grid(row=1, column=1)
frame.grid_propagate(0)
frame.grid(row=0, column=0, rowspan=2, columnspan=2)
window.mainloop()
【问题讨论】:
-
试试
frame.place(relx=0.5, rely=0.5, anchor='c')。
标签: python python-3.x tkinter centering