Q:

How to make a Tkinter label update?

I have a simple tkinter GUI with a label displaying a number and a button. I have it set to the variable x, and when button is pushed, the value of x goes up by one. However, when I hit the button, the label doesn't update. How do I do this?
from tkinter import *

x = 1
def add():
    global x
    x += 1

win = Tk()

label = Label(win, text=x)
label.pack()

button = Button(win, text="Increment", command=add)
button.pack()

win.mainloop() 

A:

Configuring the text of a label is a one shot effect. Updating the int later won't update the label.
To solve this, you can either explicitly update the label yourself:
def add():
    global x
    x += 1
    label.configure(text=x)

... Or you can use a tkinter variable like an IntVar (or more generally, a StringVar, if your text isn't just a number), which does update the label when you update the var. Don't forget to configure textvariable instead of text if you do this.
from tkinter import *

win = Tk()

x = IntVar()
x.set(1)
def add():
    x.set(x.get() + 1)

label = Label(win, textvariable=x)
label.pack()

button = Button(win, text="Increment", command=add)
button.pack()

win.mainloop()

Take care to create a Tk() instance before you create the IntVar, otherwise tkinter will throw an exception.

A:

You have to do it manually by associating a command with the click of the button. Suppose you want the text of the Label to update when you click button:
button = Button(win, text="One", command=add) # add() is called when button is clicked

Now, you define the add command/function in order to change the text in the label:
def add():
    global x
    x += 1
    label.config(text=x) # calling the method config() to change the text

