Frage

This is an example. size = 2 label = Label(tk, text=size) label.pack() size = 3 Can i update the label to say 3?

War es hilfreich?

Lösung

Yes, just used the config method:

label = Label(root,text="this is text!")
label.pack()

label.config(text="that was text!")

Another way to do this would be to set the textvariable attribute of the label.

textvar = StringVar()
textvar.set("this is text!")
label = Label(root,textvariable=textvar)
label.pack()

textvar.set("that was text!")

In this case the label instance will automatically update its text when the textvar instance is updated.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top