i new tkinter. tried code , did not work. when click of buttons(yes/no), dialog not close , print statement not print. know in swing need events print statement. same in tkinter?
from tkinter import * import tkinter.messagebox root = tk() answer=tkinter.messagebox.askquestion('question','what name?') if answer=='yes': print('i king') root.mainloop()
how go correcting it?
the returned value 'yes'
(all lowercase) , trying check against 'yes'
, hence not print. try checking against 'yes'
.
also, actual application root
not close until click on x
button, because defining tk()
application , entering mainloop. if want close (and program end print statement) , not need root=tk()
or root.mainloop()
.
example -
import tkinter.messagebox answer=tkinter.messagebox.askquestion('question','what name?') if answer=='yes': print('i king')
please note, print 'i king'
console.
to answer question in comment -
is there way can hide dialog box called tk-- second 1 in background?
you have create application using tk()
that, , can use root.withdraw()
on it. example -
import tkinter.messagebox tkinter import tk root = tk() root.withdraw() answer=tkinter.messagebox.askquestion('question','what name?') if answer=='yes': print('i king')
Comments
Post a Comment