user9180455
user9180455

Reputation:

Display text on a Tkinter label

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?

Upvotes: 0

Views: 1139

Answers (1)

adder
adder

Reputation: 3688

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.

Upvotes: 1

Related Questions