Problem with threads and Tkinter user-generated events on Solaris

Eric Brunel eric.brunel at
Fri Dec 7 17:21:02 CET 2001

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)

Button(root, command=click, text='Send').pack()

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