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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:15:11+00:00 2026-06-02T14:15:11+00:00

I am experimenting with Tkinter for the first time, and am trying to call

  • 0

I am experimenting with Tkinter for the first time, and am trying to call a function when a button is clicked. This is part of my code. mt is referring to a label that I have made dynamic by attaching it to a label so that I can change what the label says. I want the user to be able to type in something into an entry box, hit the button, and the it will change the label to what was typed.

    def new(self):
        mt.set("New")
        e1 = Entry(master)
        e1.pack()
    def new_ok(self):
        mt.set("OK")
        #the next part is what I need help with
        if (checks if button has been clicked) button has been clicked:
            mt.set("#what it says in the entry box#")

How should I do this? I have looked on tutorials and read them but none of them have clearly acknowledged how to check if a button has been pressed and to respond.

  • 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-02T14:15:13+00:00Added an answer on June 2, 2026 at 2:15 pm

    If the question is: “How do you update a Label widget?”
    then the answer is with the widget’s configure method.

    # Tkinter in Python 2.7 & tkinter in 3.2
    import Tkinter as tk
    
    class GUI(tk.Tk):
        def __init__(self):
            tk.Tk.__init__(self)
    
            bF = tk.Frame(self, bd=8, relief='sunken')
            bF.pack(expand='true', fill='x')
            changeButton = tk.Button(bF, text='Change', bd=4, fg='white',
                                    relief='groove', activebackground='green',
                                    command=self.change_label)
            changeButton.pack()
    
            self.entryLabel = tk.Label(self, text='Hello')
            self.entryLabel.pack()
    
            self.mEntry = tk.Entry(self, bd=4, relief='sunken')
            self.mEntry.pack()
    
        def change_label(self):
            data = self.mEntry.get()
            self.entryLabel.configure(text=data)
    
    
    gui = GUI()
    gui.mainloop()
    

    You will want to make your GUI a class like in this example;
    that way you can use the self. prefix to refer to the widget made in another method.

    In your example it looks like you might be saying ‘mt’ is a control variable.
    The answer would still be to make a class, so that you can use the self. prefix.

    The control variable likely isn’t necessary unless you would want
    the label to be updated as you changed the contents of the Entry widget:

    import Tkinter as tk
    
    class GUI(tk.Tk):
        def __init__(self):
            tk.Tk.__init__(self)
    
            bF = tk.Frame(self, bd=8, relief='sunken')
            bF.pack(expand='true', fill='x')
    
            var = tk.StringVar()
            var.set('Hello')
            entryLabel = tk.Label(self, textvariable=var)
            entryLabel.pack()
    
            mEntry = tk.Entry(self, bd=4, relief='sunken', textvariable=var)
            mEntry.pack()
    
    gui = GUI()
    gui.mainloop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am experimenting with Tkinter, as I was trying to figure out is there
While experimenting with this question on collections in Spring.NET , I discovered that Spring
While experimenting a bit with C++ templates I managed to produce this simple code,
Experimenting with Cocos2D collection detection and have some questions. First, some background: This is
In experimenting with this question I created an example that I utterly do not
Experimenting with jQuery and trying to make a small slide show that rotates through
I experimenting with jQuery. As I was trying I found out that I can't
Experimenting with Scala... I'm trying to define something analogous to the @ hack in
When experimenting with (embedded) Apache Derby DB, I noticed that a fresh database, with
I'm experimenting with android terminal emulator( Terminal IDE ) and trying to compile an

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.