我有一个创建窗口的简单脚本:
import Tkinter as tk
def center(win):
win.update_idletasks()
width = win.winfo_width()
frm_width = win.winfo_rootx() - win.winfo_x()
win_width = width + 2 * frm_width
height = win.winfo_height()
titlebar_height = win.winfo_rooty() - win.winfo_y()
win_height = height + titlebar_height + frm_width
x = win.winfo_screenwidth() // 2 - win_width // 2
y = win.winfo_screenheight() // 2 - win_height // 2
win.geometry('{}x{}+{}+{}'.format(width, height, x, y))
def showDialog():
print "tkinter"
root = tk.Tk()
root.title("Say Hello")
label = tk.Label(root, text="Hello World")
label.pack(side="top", fill="both", expand=True, padx=20, pady=20)
button = tk.Button(root, text="OK", command=lambda: root.destroy())
button.pack(side="bottom", fill="none", expand=True, padx=10, pady=10)
center(root)
root.attributes("-topmost", True)
root.mainloop()
showDialog()
运行此脚本时,第一个空窗口将显示在屏幕的左上角,然后完整的窗口将显示在屏幕的中央。在
我不想看到第一个空窗口(它只出现了几毫秒,但这不太好)
我怎么能做到呢?在
使用以下两种方法隐藏或显示根窗口。在
当您将根窗口的大小设为},请使用
^{pr2}$(1, 1)
居中时,您应该将窗口大小设置为center method
。^此处不需要{
command=root.destroy
。在相关问题 更多 >
编程相关推荐