It'*_*lem 2 python tkinter centering
我正在使用Python制作一个程序,我希望在中心使用一组按钮.如何使用pack()创建按钮中心?
Ado*_*rea 11
如果这不能解决您的问题
button.pack(side=TOP)
Run Code Online (Sandbox Code Playgroud)
您需要使用该方法
button.grid(row=1,col=0)
Run Code Online (Sandbox Code Playgroud)
row=1,col=0窗口中其他窗口小部件的位置依赖值
或者你可以使用 .place(relx=0.5, rely=0.5, anchor=CENTER)
button.place(relx=0.5, rely=0.5, anchor=CENTER)
Run Code Online (Sandbox Code Playgroud)
示例使用.place():
from tkinter import * # Use this if use python 3.xx
#from Tkinter import * # Use this if use python 2.xx
a = Button(text="Center Button")
b = Button(text="Top Left Button")
c = Button(text="Bottom Right Button")
a.place(relx=0.5, rely=0.5, anchor=CENTER)
b.place(relx=0.0, rely=0.0, anchor=NW)
c.place(relx=1.0, rely=1.0, anchor=SE)
mainloop
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
22845 次 |
| 最近记录: |