Search code examples
pythongtkpygtkpango

How should I display a constantly updating timer using PyGTK?


I am writing a timer program in Python using PyGTK. It is precise to the hundredths place. Right now, I am using a constantly updated label. This is a problem, because if I resize the window while the timer is running, Pango more often than not throws some crazy error and my program terminates. It's not always the same error, but different ones that I assume are some form of failed draw. Also, the label updates slower and slower as I increase the font size.

So, I am wondering if there is a more correct way to display the timer. Is there a more stable method than constantly updating a label?


Solution

  • I figured out the problem. It was indeed a problem with the threads. I never would've guessed that myself. The trick is to use gobject.timeout_add() to create a timer instead of a threaded loop. Here is some information about gobject.timeout_add():

    http://faq.pygtk.org/index.py?req=show&file=faq01.021.htp

    Don't forget to have your function return True, or the timer will stop.