I have a simple script that creates a window:
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()
When running this script, a first empty window is displayed on the top left part of the screen and then the complete window is displayed centered in the screen.
I would like to not see this first empty window (it appears only for few milliseconds, but this is not nice)
How can I do that ?
withdraw
method, and usedeiconify
to re-display it. - PM 2Ringwin.update_idletasks()
? - furaswin.update_idletasks()
does not help (behavior not changed) - Laurent D.