Problem with callbacks from C to Python

Eric Brunel eric.brunel at pragmadev.com
Mon Jan 7 04:59:25 EST 2002


> BTW, I also tried doing some sort of hack with custom bindings, to no
> avail. What I could use is some way to post an event to the TCL/Tk event
> queue...

We encountered the same kind of problem, and we solved it just the way you 
describe: posting an event in the Tk event queue. This can be achieved very 
simply by doing:
<Tkinter widget>.event_generate("<<callback>>", when='head')
The first arg to event_generate is a custom event type, so you can put 
anything you like, but it must be between "<<...>>". The "when='head'" 
stuff ensures that the event will be put in the Tk event queue, in front of 
all other pending events. Please note that the default is to treat the 
event immediatly, without even putting it in the event queue. So you're 
likely to run into the same problems if you omit it.

The binding you'd do to treat this event would be:
<Tkinter widget>.bind("<<callback>>", yourCallbackFunction)

BTW, we also solved the Python crash problem completely differently; our 
way is far more complicated, but it works. So if you still have these kind 
of problems, just let us know.

HTH
 - eb -



More information about the Python-list mailing list