Changing the text on a label
self.labelText = 'change the value'
The above sentence makes labelText change the value, but not change depositLabel's text.
To change depositLabel's text, use one of following setences:
self.depositLabel['text'] = 'change the value'
OR
self.depositLabel.config(text='change the value')
You can also define a textvariable
when creating the Label, and change the textvariable to update the text in the label.Here's an example:
labelText = StringVar()depositLabel = Label(self, textvariable=labelText)depositLabel.grid()def updateDepositLabel(txt) # you may have to use *args in some cases labelText.set(txt)
There's no need to update the text in depositLabel
manually. Tk does that for you.
Use the config
method to change the value of the label:
top = Tk()l = Label(top)l.pack()l.config(text = "Hello World", width = "50")