如何在屏幕中央显示按钮?(不是屏幕在窗口中央。)

时间:2019-10-17 09:09:32

标签: python tkinter

from tkinter import *
root = Tk()
root.geometry("500x500+0+0")
startbutton = Button(anchor=CENTER, text="Start",height=1,width=4)
startbutton.pack()
root.mainloop()

这是我的代码,按钮仅显示在x轴的中心。

1 个答案:

答案 0 :(得分:1)

使用tkinter功能获取屏幕尺寸

screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()

然后设置它的位置