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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:50:39+00:00 2026-05-14T05:50:39+00:00

I wrote a Python script that does some task to generate, and then keep

  • 0

I wrote a Python script that does some task to generate, and then keep changing some text stored as a string variable. This works, and I can print the string each time it gets changed.

I can get the Label to display the string for the first time, but it never updates.

Here’s my code:

from tkinter import *

outputText = 'Ready'
counter = int(0)

root = Tk()
root.maxsize(400, 400)

var = StringVar()

l = Label(root, textvariable=var, anchor=NW, justify=LEFT, wraplength=398)
l.pack()

var.set(outputText)

while True:
    counter = counter + 1
    outputText = result
    outputText = result
    outputText = result
    if counter == 5:
        break

root.mainloop()

The Label will show Ready, but won’t update to change that to the strings as they’re generated later.

After a fair bit of googling and looking through answers on this site, I thought the solution might be to use update_idletasks. I tried putting that in after each time the variable was changed, but it didn’t 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-05-14T05:50:40+00:00Added an answer on May 14, 2026 at 5:50 am

    The window is only displayed once the mainloop is entered. So you won’t see any changes you make in your while True block preceding the line root.mainloop().


    GUI interfaces work by reacting to events while in the mainloop. Here’s an example where the StringVar is also connected to an Entry widget. When you change the text in the Entry widget it automatically changes in the Label.

    from tkinter import *
    
    root = Tk()
    var = StringVar()
    var.set('hello')
    
    l = Label(root, textvariable = var)
    l.pack()
    
    t = Entry(root, textvariable = var)
    t.pack()
    
    root.mainloop() # the window is now displayed
    

    I like the following reference: tkinter 8.5 reference: a GUI for Python


    Here is a working example of what you were trying to do:

    from tkinter import *
    from time import sleep
    
    root = Tk()
    var = StringVar()
    var.set('hello')
    
    l = Label(root, textvariable = var)
    l.pack()
    
    for i in range(6):
        sleep(1) # Need this to slow the changes down
        var.set('goodbye' if i%2 else 'hello')
        root.update_idletasks()
    

    root.update Enter event loop until all pending events have been processed by Tcl.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 444k
  • Answers 444k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I solved the pesky issue by delegating the computing to… May 15, 2026 at 6:34 pm
  • Editorial Team
    Editorial Team added an answer capture the users window resolution and set the overlay's width… May 15, 2026 at 6:34 pm
  • Editorial Team
    Editorial Team added an answer The tools package is part of R itself. CRAN has… May 15, 2026 at 6:34 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.