0

I would like to know how to display text or a number to an empty label, after a button is clicked. Let's pretend, I want to display the number "0" to an empty label after a button is clicked.

My questions in simplified form are:

  1. How to set a numeric value of 0 to a button.

  2. Once the numeric integer value of (0) is set, how do you display the result to an empty label after the button widget is clicked?

1 Answer 1

1

You need to bind a callback helper method which would be triggered when the button is clicked. Here's an MCVE:

import tkinter as tk

root = tk.Tk()

label = tk.Label(root)
label.pack()

button = tk.Button(
    root,
    text='Click Me!',
    command=lambda: label.configure(text='beautiful spam')
)
button.pack()

root.mainloop()

...you'd do the same for 0 - the text doesn't matter, nor does it matter whether you're configuring an empty label, or a label which already has some text.

1
  • Thanks for your time, this is exactly what I needed. 😊
    – user9180455
    Commented Jan 6, 2018 at 8:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.