Skip to content Skip to sidebar Skip to footer

How Do I Update/redraw A Gtk Widget (gtklabel) Internally Without A Key Press Event Using Python?

I have some code below that is attempting to update a GTK Label element. I'm including two files: the ui file and the py file. UI file:

Solution 1:

You'll want to use the Widget's queue_draw function:

The queue_draw_area() method invalidates the rectangular area of the widget (...) by calling the gtk.gdk.Window.invalidate_rect() method on the widget's window and all its child windows.

But, as you are already doing that in your set method, my guess is that the

ifhasattr(item,'show')

check prevents the item from updating. Another check is to call the queue_draw function on the entire window, and see if that updates things.

Alternatively, force the events that are queued to be processed as follows:

while gtk.events_pending():
    gtk.main_iteration_do(True)

Solution 2:

One thing that happens in the code is that while do_something_that_takes_a_while is executed, no events are being processed. One way to solve that is to force event processing at some point inside that method:

--- code.py 2011-12-05 10:32:53.000000000 +0100+++ code.py.bak 2011-12-05 10:27:22.000000000 +0100@@ -95,8 +95,6 @@
         timeout = 15
         while timeout != 0:
             self.set('l1','%s' % timeout)
-            while gtk.events_pending():-                gtk.main_iteration()
             wait(1)
             timeout -= 1
             print timeout

Post a Comment for "How Do I Update/redraw A Gtk Widget (gtklabel) Internally Without A Key Press Event Using Python?"