Strange Tkinter behaviour

Tomasz Lisowski jtlispl at poczta.NOSPAM.onet.pl
Thu Nov 29 01:28:00 EST 2001


Hi,

I am using a CAD system having an embedded Python 2.0 support. The producer
has created some Python modules giving access to the system internals. Among
other things there is a module with functions supporting the creation of
geometrical entities in the drawing.

I have created a script using Tkinter as GUI, which is a lot better, than a
GUI module provided by the CAD system producer (written as a C language
module and frozen into the interpreter, linked with the application), and
have encountered some strange behaviour, described below.

root = Tk()
app = App(root)
root.mainloop()

That's the usual part. The window created by the App class has a button,
which is supposed to add text to the drawing. Its action is described below
(by 'native' module I mean the module provided by the CAD system producer,
giving access to the drawing):

Step 1: Withdraw the root window, so that the user can see the whole drawing
Step 2: Use native module to get a point in the drawing
Step 3: Use native module to place text at this point
Step 4: Deiconify the root window

The strange fact is, that the text does NOT appear immediately after
completing Step 3. The text given to be drawn in the drawing appears only if
I terminate the macro (root is destroyed), or click the button again to add
some more text. What is the reason of this delay? I suspected some
event-related things, so I have used update() method, but this did not help.

What makes it even more strange is, that a simple test using Step 2 and Step
3 only, when the root widget is not yet created, displays the text
immediately.

There must be a problem with interaction between the Tkinter event loop and
the native module functionality. If Steps 2 and 3 are performed, when the
event loop is not running, everything is fine. If this is done, while the
Tkinter window is functionning (event loop is running), I observe this
delay - the text appears either after the event loop termination, or after
the button is used again.

I would be very grateful for some hints. Currently I have designed this
window to quit the event loop after using this button, so the user has to
invoke the script again in order to add more text. Of course, this is not
user friendly :-)

Thanks in advance
Tomasz Lisowski





More information about the Python-list mailing list