How to change Tkinter label text on button press

后端 未结 2 1118
故里飘歌
故里飘歌 2021-01-14 10:15

I have this code, and its meant to change the text of the Instruction label when the item button is pressed. It doesn\'t for some reason, and I\'m not entirely

2条回答
  •  生来不讨喜
    2021-01-14 11:13

    You can make message a StringVar to make callback.

    message = tkinter.StringVar()
    
    message.set('Not pressed.')
    

    You need to set message to be a textvariable for Instruction:

    Instruction = tkinter.Label(Tk, textvariable=message, font='size, 20').pack()

    and then

    def press():
        message.set('Button Pressed')
    

提交回复
热议问题