from Tkinter import *
import tkMessageBox
import sys
tk = Tk()
Button(tk, text="Exit", command=sys.exit).pack()
tkMessageBox.showinfo("Test app", "Click on Ok, then on Exit.\n"
+ "Do you see the problem?")
tk.mainloop()
(The application doesn't respond to mouse clicks after dismissing the
message box.)
Any suggestions? I think the problem is caused by the call to `showinfo'
before the Tk message loop is entered. But my startup code needs to
display some information.
Florian Weimer schreef:
> tk = Tk()
> Button(tk, text="Exit", command=sys.exit).pack()
> tkMessageBox.showinfo("Test app", "Click on Ok, then on Exit.\n"
> + "Do you see the problem?")
> tk.mainloop()
>
> (The application doesn't respond to mouse clicks after dismissing the
> message box.)
Displaying a message box outside the main loop seems to mess up tk's
message dispatching somehow. One way to work around this is to use a
separate Tk instance and throw it away after displaying the message:
tk = Tk()
Button(tk, text="Exit", command=sys.exit).pack()
xxx = Tk()
xxx.withdraw()
tkMessageBox.showinfo("Test app", "Click on Ok, then on Exit.\n"
+ "Do you still see the problem?", master=xxx)
xxx.destroy()
tk.mainloop()
--
Niels Diepeveen
Endea automatisering
> Displaying a message box outside the main loop seems to mess up tk's
> message dispatching somehow. One way to work around this is to use a
> separate Tk instance and throw it away after displaying the message:
> tk = Tk()
> Button(tk, text="Exit", command=sys.exit).pack()
> xxx = Tk()
> xxx.withdraw()
> tkMessageBox.showinfo("Test app", "Click on Ok, then on Exit.\n"
> + "Do you still see the problem?", master=xxx)
> xxx.destroy()
> tk.mainloop()
Another possibilty (which I actually use): Calling the initialization
code from the main loop (using Tk.after_idle).