Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8359107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:02:20+00:00 2026-06-09T11:02:20+00:00

I was trying to build a simple stopwatch app using py-gtk. Here is the

  • 0

I was trying to build a simple stopwatch app using py-gtk. Here is the callback function for the toggle button in my stopwatch window.

def start(self,widget):
    if widget.get_active():         
        widget.set_label('Stop')
    else: 
        self.entry.set_text(str(time.time() - s))   
        widget.set_label('Start')

It works perfectly well except for the fact that time does not get continuously get displayed in the entry widget. If I add an infinite while loop inside the ‘If ‘ condition like ,

while 1:
    self.entry.set_text(str(time.time() - s))

the window becomes unresponsive. Can someone help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:02:21+00:00Added an answer on June 9, 2026 at 11:02 am

    Use gobject.timeout_add:

    gobject.timeout_add(500, self.update)
    

    to have gtk call self.update() every 500 milliseconds.

    In the update method check if the stopwatch is active and call

    self.entry.set_text(str(time.time() - s))   
    

    as necessary.


    Here is fairly short example which draws a progress bar using gobject.timeout_add:

    import pygtk
    pygtk.require('2.0')
    import gtk
    import gobject
    import time
    
    class ProgressBar(object):
        def __init__(self):
            self.val = 0
            self.scale = gtk.HScale()
            self.scale.set_range(0, 100)
            self.scale.set_update_policy(gtk.UPDATE_CONTINUOUS)
            self.scale.set_value(self.val)
            gobject.timeout_add(100, self.timeout)
        def timeout(self):
            self.val += 1
            # time.sleep(1)
            self.scale.set_value(self.val)
            return True
    
    def demo_timeout_add():
        # http://faq.pygtk.org/index.py?req=show&file=faq23.020.htp
        # http://stackoverflow.com/a/497313/190597
        win = gtk.Window()
        win.set_default_size(300, 50)
        win.connect("destroy", gtk.main_quit)
        bar = ProgressBar()
        win.add(bar.scale)
        win.show_all()
        gtk.main()
    
    demo_timeout_add()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a simple JQ Plugin with input and a button: (function
I'm trying to build a simple Android application using NDK. Here are the contents
I am trying to build a simple todo list using google app engine in
I am trying to build simple web app using primefaces 3.0.M2 version. I am
I'm trying to build a simple Maps app based on the hello map tutorial
Im trying to build a simple, lightweight product viewer using jquery. I have a
I am trying to build a simple metronome app and I am wondering if
I am trying to build a simple search-engine using HtmlAgilityPack and Xpath with C#
I am trying to build a simple worker function that takes a config of
I'm trying to build a simple Silverlight 3 MediaPlayer using the MediaElement tag: <Border

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.