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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:41:49+00:00 2026-06-02T07:41:49+00:00

I would like the code to run in the background and to update my

  • 0

I would like the code to run in the background and to update my GUI periodically. How can I accomplish this?

For example, suppose I want to execute something like this in the background of the GUI code you can see below:

x = 0

while True:
   print(x)
   x = x + 1
   time.sleep(1)

This is the GUI code:

class GUIFramework(Frame):

    def __init__(self,master=None):
        Frame.__init__(self,master)
        self.master.title("Volume Monitor")
        self.grid(padx=10, pady=10,sticky=N+S+E+W)
        self.CreateWidgets()

    def CreateWidgets(self):
        textOne = Entry(self, width=2)
        textOne.grid(row=1, column=0)

        listbox = Listbox(self,relief=SUNKEN)
        listbox.grid(row=5,rowspan=2,column=0,columnspan=4,sticky=N+W+S+E,pady=5)
        listbox.insert(END,"This is an alert message.")

if __name__ == "__main__":
    guiFrame = GUIFramework()
    guiFrame.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-02T07:41:51+00:00Added an answer on June 2, 2026 at 7:41 am

    It is a little unclear what your code at the top is supposed to do, however, if you just want to call a function every second (or every the amount of seconds you want), you can use the after method.

    So, if you just want to do something with textOne, you’d probably do something like:

    ...
    textOne = Entry(self, width=2)
    textOne.x = 0
    
    def increment_textOne():
        textOne.x += 1
    
        # register "increment_textOne" to be called every 1 sec
        self.after(1000, increment_textOne) 
    

    You could make this function a method of your class (in this case I called it callback), and your code would look like this:

    class Foo(Frame):
    
        def __init__(self, master=None):
            Frame.__init__(self, master)
            self.x = 0
            self.id = self.after(1000, self.callback)
    
        def callback(self):
            self.x += 1
            print(self.x)
            #You can cancel the call by doing "self.after_cancel(self.id)"
            self.id = self.after(1000, self.callback)  
    
    gui = Foo()
    gui.mainloop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to run some code onload of a form in WPF. Is
I have JSF code like: <h:inputText id=from value=#{fromToMBean.fromName}/> I would like to get this
Problem: I would like to share code between multiple assemblies. This shared code will
I would like to track (run some code - or invoke function) when the
I would like to have my Python program run in the background as a
I would like a command line function that I can run on any file
I would like to be able to do something like (psuedo-code): if (classAvailable) {
I'm searching for the cleanest solution here. I would like to code a stored
I have a simple model from simulink and I would like to generate code
Would like to know the c# code to actually retrieve the IP type: Static

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.