Problem with threads and Tkinter user-generated events on Solaris

Xiao-Qin Xia xx758 at cam.ac.uk
Fri Dec 7 12:49:00 EST 2001


Hi,

Did you try Python 2.0?
My Python+Tkinter thread application can run under Python 2.0, but will die
under Python 2.1.

Cheers,
Xiao-Qin Xia


"Eric Brunel" <eric.brunel at pragmadev.com> wrote in message
news:9uqmm4$1lcu$1 at norfair.nerim.net...
> Hi all,
>
> We're writing a Python+Tkinter application and we encountered a strange
> problem when trying to generate Tkinter events from another thread than
the
> main one. Here is a short script showing the problem:
>
> ===
> from Tkinter import *
> from threading import Thread
>
> root = Tk()
>
> def f(*whatever): print 'yeah'
>
> root.bind('<<go>>', f)
>
> def sendEvt():
>   print 'generating'
>   root.event_generate('<<go>>', when='head')
>
> thread = 1
>
> def click():
>   if thread:
>     th = Thread(None, sendEvt)
>     th.start()
>   else:
>     sendEvt()
>
> Button(root, command=click, text='Send').pack()
> root.mainloop()
> ===
>
> Basically, clicking on the "Send" button generates an event that should be
> treated by the binding on the root widget. Depending on the value of the
> "thread" variable, the event is generated either in the main thread or in
a
> secondary thread.
>
> We tested this program with Python 2.1, Tcl/Tk 8.3 on Linux Mandrake 8.0,
> Solaris 2.7 and Windows 2000. Here is what happens:
> - when the "thread" variable is 0, the program works everywhere.
> - when the "thread" variable is 1, the program works on Linux and Windows,
> but not on Solaris: the event is generated, but never received (the
binding
> never triggers).
>
> Is this a known problem? Does anybody have a patch for Solaris correcting
> this behaviour? We already found a workaround, but it's quite ugly. And it
> would be really nice to have an application that is 100% portable between
> Windows and all Unices.
>
> Thanks a lot in advance.
>  - eric -
>





More information about the Python-list mailing list