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

  • Home
  • SEARCH
  • 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 7431597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:19:13+00:00 2026-05-29T09:19:13+00:00

I am developing an app in python with pyGtk+Glade. I want to execute a

  • 0

I am developing an app in python with pyGtk+Glade.

I want to execute a function every N seconds (just like in javascript the function setTimeout()). If the user perform a click, some action must be done, and the timer must be reset.

I was trying with threading.Timer, something like this:

def callback():
    print "callback executed"

t = threading.Timer(10.0, callback)
t.start()

but it doesn’t work for me because it blocks everything for the N secs and doesn’t capture the user click.

Any other option?

  • 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-05-29T09:19:13+00:00Added an answer on May 29, 2026 at 9:19 am

    This creates a timer which calls MainWin.update() every second. When the button is pressed, the current timer is killed and a new timer is started.

    import pygtk
    pygtk.require('2.0')
    import gtk
    import gobject
    import time
    
    class MainWin(object):
        def destroy(self, widget, data=None):
            gtk.main_quit()
        def __init__(self):
            self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
            self.window.connect("destroy", self.destroy)
            self.window.set_border_width(10)
            self.button = gtk.Button("Reset")
            self.button.connect("clicked", self.onclick)
            self.window.add(self.button)
            self.button.show()
            self.window.show()
            self.reset_timer = False
            self.count = 0
            self.duration = 1000
            self.timer = gobject.timeout_add(self.duration, self.update)
        def reset(self):
            print('Resetting timer')
            gobject.source_remove(self.timer)
            # start a new period call to update
            self.count = 0        
            self.timer = gobject.timeout_add(self.duration, self.update) 
        def onclick(self, widget):
            # Every action which resets the timer should call self.reset_timer().
            self.reset()
        def update(self):
            print('{t:.1f}: count = {i}'.format(t=time.time() % 100, i=self.count))
            self.count += 1
            return True
        def main(self):
            gtk.main()
    
    if __name__=='__main__':
        MainWin().main()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing in Google App Engine (python sdk) and I want to use jQuery
I'm developing an app (an API) in python and I would like to offer
I am developing a Python App Engine app, where I want to split the
I'd like to use python scripts as plugins for an app I'm developing. This
I've been developing a Facebook app using Google App Engine in Python and the
I'm developing a Django app, and I'm trying to use Python's logging module for
I have a python app, that I'm developing. There is a need to use
I learning Python (coming from a dotnet background) and developing an app which interacts
Is NetBeans recommended for developing a GUI for a Python app? Does it have
I am developing an application on the Google App Engine using Python (and Django,

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.