GTK + is not thread safe, so you shouldn't just call GUI update methods from other threads. glib.idle_add (or gobject.idle_add in older versions of PyGTK) can be used for this purpose.
Instead of writing:
label.set_text("foo")
you write:
glib.idle_add(label.set_text, "foo")
which calls a function call in GTK +.
If you need to run multiple statements, it is often easier to wrap them in functions:
def idle(): label1.set_text("foo") label2.set_text("bar") glib.idle_add(idle)
Make sure that the function passed to idle_add does not return True ; otherwise it will be queued again.
Edit: As Daniel noted, you first need to call gtk.gdk.threads_init() anywhere in your program.
Johannes Sasongko
source share