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 8644883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:24:32+00:00 2026-06-12T12:24:32+00:00

My Tkinter-based program needs to periodically perform some heavy maintenance functions. Since it is

  • 0

My Tkinter-based program needs to periodically perform some “heavy” maintenance functions.
Since it is a program that is running continuously, I was thinking of launching those functions only after a given amount of idle time.

How do you do it in Tkinter? I found about about after_idle in http://etutorials.org/Programming/Python+tutorial/Part+III+Python+Library+and+Extension+Modules/Chapter+16.+Tkinter+GUIs/16.9+Tkinter+Events/, but that gets called just when the event loop is idle. I need it to run my functions, say, after 10 minutes of idle time instead.

~~~

Mr.Steak gave the answer I needed – I just modified it slightly as follows to be able to perform different tasks at different intervals, using the idletime variable :

import time
from Tkinter import *

root = Tk()


def resetidle(*ignore): 
    global idletime
    for k in idletime: k['tlast']=None

def tick(*ignore):
    global idletime 
    t=time.time()   # the time in seconds since the epoch as a floating point number
    for k in idletime:
        if not k['tlast']:
            k['tlast'] = t
        else:
            if t-k['tlast']>k['tmax']:
                k['proc']()
                k['tlast'] = None
    root.after(5000, tick)   # reset the checks every 5''

idletime=[{'tlast':None,'tmax':60,'proc':test1},               # every 1'
      {'tlast':None,'tmax':3600,'proc':test2}]    # every 1h
root.after(5000, tick)
root.bind('<Key>', reset)
root.bind('<Button-1>', reset)
root.mainloop()
  • 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-12T12:24:34+00:00Added an answer on June 12, 2026 at 12:24 pm

    In the following example, the tick function is called every second. After 5 seconds, a message is printed, unless a key or mouse button 1 were pressed.

    import time
    from Tkinter import *
    
    root = Tk()
    running = None
    
    def reset(*ignore): 
        global running
        running = None
    
    def tick(*ignore):
        global running
        if not running:
            running = time.time()
        elif time.time() - running > 5:
            print 'I waited 5 seconds...'
            running = None
        root.after(1000, tick)   
    
    root.after(1000, tick)    
    root.bind('<Key>', reset)
    root.bind('<Button-1>', reset)
    root.mainloop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on a Gui-based program using Tkinter. It needs data to
I have a python-tkinter gui app that I've been trying to find some way
I am writing a Tkinter program that requires a loop. I can't run the
I am writing a tkinter program that is kind of a program that is
I am running an app using twisted and tkinter that sends the result to
I have a python based tkinter script which executes some commands using subprocess module.
Specs: Python2.7.1 Tkinter (Tk version 8.5) Windows7 IDLE 2.7.1 I'm coding a program that
I wrote a simple Tkinter based Python application that reads text from a serial
I have a py27-tkinter macport installed and it seems that it is compiled without
I need to create a simple windows based GUI for a desktop application that

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.