Changing the text on a label

前端 未结 6 1508
长情又很酷
长情又很酷 2020-11-28 10:43

I am having trouble with using a key binding to change the value of a label or any parameter. This is my code:

from tkinter import*

class MyGUI:
  def __ini         


        
6条回答
  •  無奈伤痛
    2020-11-28 10:43

    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.

提交回复
热议问题