Python: Tkinter Askyesno Method Opens An Empty Window
I use this to get yes/no from user but it opens an empty window: from Tkinter import * from tkMessageBox import * if askyesno('Verify', 'Really quit?'): print 'ok' And this e
Solution 1:
Tkinter requires that a root window exist before you can create any other widgets, windows or dialogs. If you try to create a dialog before creating a root window, tkinter will automatically create the root window for you.
The solution is to explicitly create a root window, then withdraw it if you don't want it to be visible.
You should always create exactly one instance of Tk
, and your program should be designed to exit when that window is destroyed.
Solution 2:
Create root window explicitly, then withdraw.
fromTkinterimport *
from tkMessageBox import *
Tk().withdraw()
askyesno('Verify', 'Really quit?')
Not beautiful solution, but it works.
UPDATE
Do not create the second Tk window.
from Tkinter import *
from tkMessageBox import *
root = Tk()
root.withdraw()
showinfo('OK', 'Please choose')
root.deiconify()
# Do not create another Tk window. reuse root.
root.title("Report month")
...
Post a Comment for "Python: Tkinter Askyesno Method Opens An Empty Window"