Why am I getting ugly curly brackets around my text in the label widget? - Tkinter

末鹿安然 提交于 2019-12-01 06:45:58
self.label["text"] = "Total tries: 0",

There is a comma at the end of the line. The comma changes the value being assigned to self.label["text"] from a string to a tuple. Remove the comma, and the curly braces get removed.

I don't know why that happens; however, when I've used Tkinter, I've always done text updates either with a StringVar or using the config method. Here's a page with some examples.

Example using a StringVar:

# in class Memory

def create_widgets(self):
  self.labelText = StringVar()
  self.label = Label(self, textvariable = self.labelText)
  ... rest of method ...

def update_tries(self):
  self.labelText.set("Total tries: " + str(self.tries))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!