2

I need to generate virtual events for a tkinter window running in a separate thread. Calling event_generate from non-gui thread is supposed to be safe and it works well, when tkinter runs in the main thread and events are generated in another thread.

For a certain reason I need that the statements generating the events run in main thread (more specifically, I want those statements to be in the toplevel of the module).

But, when I do root = Tk(); root.mainloop() in a new thread and root.event_generate("<<my-event>>") in the main thread, I get stack overflow. When I swap the threads (root = Tk(); root.mainloop() in the main thread and root.event_generate("<<my-event>>") in a new thread) then everything works again.

I have taken care that root is fully construted (and also idle), before I try generating the event.

Any ideas how to get this setup working?

(I'm using Python 3.2.3)

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
Aivar
  • 6,814
  • 5
  • 46
  • 78

1 Answers1

1

Found the answer myself: put only root.mainloop() in secondary thread, keep root = Tk() in main thread.

Aivar
  • 6,814
  • 5
  • 46
  • 78
  • Damn it, Linux and OS X require tkinter to be run in main thread only: http://stackoverflow.com/a/1835036/261181 – Aivar Jul 31 '12 at 18:23