Threading and tkinter

Jani Hakala jahakala at iki.fi
Sat Mar 7 03:40:26 EST 2009


gert <gert.cuykens at gmail.com> writes:

> After reading the docs and seeing a few examples i think this should
> work ?
> Am I forgetting something here or am I doing something stupid ?
> Anyway I see my yellow screen, that has to count for something :)
>
I have been using the following scheme:
  - Pass the root object to the thread object when creating the object
  - Define a event_handler: root.bind('<<SomeEvent>>', evt_handler) in
    the main thread.

  - When the thread has done something that the GUI part should now
    about, signal an event in the thread:
        root.event_generate('<<SomeEvent>>')    (no other arguments)

  - Call a method of the thread object in the event handler e.g. to get
    some data from a queue object.

This ensures that only the main thread accesses Tkinter-related things.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.py
Type: text/x-python
Size: 1126 bytes
Desc: tkinter and threading
URL: <http://mail.python.org/pipermail/python-list/attachments/20090307/1f138abe/attachment-0001.py>
-------------- next part --------------

Jani Hakala


More information about the Python-list mailing list