Is there any possible way to create a TkInter label that uses a string and a variable as the text?
For example:
name = \"bob\"
Label(root, text=\"hel
You must tell the label to change in some way.
Here you have an example. The text of the label is a textvariable text
defined as a StringVar
which can be changed whenever you want with text.set()
.
In the example, when you click the checkbox, a command change
tells the label to change to a new value (here simplified to take two values, old
and new
)
from Tkinter import Tk, Checkbutton, Label
from Tkinter import StringVar, IntVar
root = Tk()
text = StringVar()
text.set('old')
status = IntVar()
def change():
if status.get() == 1: # if clicked
text.set('new')
else:
text.set('old')
cb = Checkbutton(root, variable=status, command=change)
lb = Label(root, textvariable=text)
cb.pack()
lb.pack()
root.mainloop()