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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:57:48+00:00 2026-06-06T05:57:48+00:00

I would like to refresh tk window when I push a button, but I

  • 0

I would like to refresh tk window when I push a button, but I have been striking out. Help would be appreciated. Below is what I have tried. I would like the tk.Label line to update when I change the input box and hit refresh, but it isn’t happening.

import Tkinter as tk

class MAIN(object):
    def __init__(self, master, **kwargs):
        frame = tk.Frame(master, borderwidth=5)
        frame.grid()
        et1 = tk.Entry(frame)
        et1.insert(0, '10')
        et1.grid(row=0,column=0,sticky=tk.W)
        tk.Label(frame, text = et1.get()).grid(row=1, column=0, sticky=tk.W)
        refresh = tk.Button(frame, text='Refresh', command = frame.update())
        refresh.grid(row=2, column=0, sticky=tk.W)

root=tk.Tk()
app=MAIN(root)
root.mainloop()

Any Help would be greatly appreciated. Thanks

Edit:

I have also tried to use the update_idletasks(), but that didn’t work either.

Answer from sc0tt’s help:

import Tkinter as tk

class MAIN(object):
    def __init__(self, master, **kwargs):
        frame = tk.Frame(master, borderwidth=5)
        frame.grid()
        self.et1 = tk.Entry(frame)
        self.et1.insert(0, 10)
        self.et1.grid(row=0,column=0,sticky=tk.W)
        self.label_contents = tk.StringVar()
        self.label_contents.set(self.et1.get())
        tk.Label(frame, textvariable=self.label_contents).grid(row=1, column=0, sticky=tk.W)
        refresh = tk.Button(frame, text='Refresh', command = self.refresh_hit)
        refresh.grid(row=2, column=0, sticky=tk.W)

    def refresh_hit(self):
        self.label_contents.set(self.et1.get())

root=tk.Tk()
app=MAIN(root)
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-06T05:57:50+00:00Added an answer on June 6, 2026 at 5:57 am

    calling update/update_idletasks won’t do that for you. Here is a way of doing it using a simple lambda in the command for the button. It takes the value of the text box and alters the variable associated with the label.
    import Tkinter as tk

    class MAIN(object):
    
        def __init__(self, master, **kwargs):
            frame = tk.Frame(master, borderwidth=5)
            frame.grid()
            et1 = tk.Entry(frame)
            et1.insert(0, 10)
            et1.grid(row=0,column=0,sticky=tk.W)
            label_contents = tk.StringVar()
            label_contents.set(et1.get())
            tk.Label(frame, textvariable=label_contents).grid(row=1, column=0, sticky=tk.W)
            refresh = tk.Button(frame, text='Refresh', command = self.refresh_clicked)
            refresh.grid(row=2, column=0, sticky=tk.W)
    
        #per comments:
        def refresh_clicked(event):
            #update labels here
    root=tk.Tk()
    app=MAIN(root)
    root.mainloop()
    

    Edit: lambda replaced by function call.

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

Sidebar

Related Questions

This is quite complicated but i would like to be able to refresh a
This question seems to have been asked before, but I feel like my situation
Possible Duplicate: How to rewrite URL without refresh, like GitHub.com Hi all, I have
My LogIn action originally looked like this: return new RedirectResult(nameValueCollection[ReturnUrl]); But, I would like
I feel like I'm missing something here, but I have this datagrid which when
Would appreciate your help with something. I have an autoclick Greasemonkey for Firefox script
I found the solution myself: refresh win after stdscr . I would like to
I would like to fire a refresh event when the user presses the Escape
I would like to know how I can only refresh a specific element in
Would like to be able to set colors of headings and such, different font

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.