简体   繁体   中英

Can I Update A Label In Tkinter?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM