Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Tkinter/Win32] Message box on app start -> mouse is dead

2 views
Skip to first unread message

Florian Weimer

unread,
Jan 18, 2000, 3:00:00 AM1/18/00
to
This code doesn't work on Windows (X11 is fine, though):

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.

Niels Diepeveen

unread,
Jan 18, 2000, 3:00:00 AM1/18/00
to

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


Florian Weimer

unread,
Jan 22, 2000, 3:00:00 AM1/22/00
to
Niels Diepeveen <ni...@endea.demon.nl> writes:

> 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).

0 new messages