Updating a python Tkinter frame

后端 未结 2 1525
盖世英雄少女心
盖世英雄少女心 2021-01-23 05:29

I am having difficulty updating a python Tkinter frame. I draw the frame with some labels and text fields, when a person presses a button, I want to do some calculations and up

相关标签:
2条回答
  • 2021-01-23 05:59

    Your problem is that you do not attach the Variable to the widget. In addition you need to use a StringVar, as the Label Widget operates on Strings and not Ints.

    Try something like:

    self.countStr = StringVar()
    self.countStr.set(str(self.count))
    Label(self.countFrame, textvariable=self.countStr).pack(side=RIGHT, padx=5)
    

    Tk updates the display when the eventloop is idle. So you need to re-enter the event loop after you set the new value.

    0 讨论(0)
  • 2021-01-23 06:13

    You should try destroying the label itself and making it again in the code with the updated text and use self.root.update()

    0 讨论(0)
提交回复
热议问题