Changing the text on a label

前端 未结 6 1518
长情又很酷
长情又很酷 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:55

    Here is another one, I think. Just for reference. Let's set a variable to be an instantance of class StringVar

    If you program Tk using the Tcl language, you can ask the system to let you know when a variable is changed. The Tk toolkit can use this feature, called tracing, to update certain widgets when an associated variable is modified.

    There’s no way to track changes to Python variables, but Tkinter allows you to create variable wrappers that can be used wherever Tk can use a traced Tcl variable.

    text = StringVar()
    self.depositLabel = Label(self.__mainWindow, text = self.labelText, textvariable = text)
                                                                        ^^^^^^^^^^^^^^^^^
      def depositCallBack(self,event):
          text.set('change the value')
    

提交回复
热议问题