I’m getting curly brackets around the text in my label widget. The output is {Total tries: 0}
instead of Total tries: 0
.
Here is a short version of my code:
JavaScript
x
27
27
1
class Cell:
2
def check(self):
3
mem.tries += 1
4
mem.update_tries()
5
6
class Memory(Frame):
7
def __init__(self, master):
8
super(Memory, self).__init__(master)
9
self.grid()
10
self.create_widgets()
11
self.tries = 0
12
13
def create_widgets(self):
14
self.label = Label(self)
15
self.label["text"] = "Total tries: 0",
16
self.label["font"] = ("Helvetica", 11, "italic")
17
self.label.grid(row = 7, columnspan = 7, pady = 5)
18
19
def update_tries(self):
20
self.label["text"] = "Total tries: " + str(self.tries)
21
22
root = Tk()
23
root.title("Memory")
24
root.geometry("365x355")
25
mem = Memory(root)
26
root.mainloop()
27
Advertisement
Answer
JavaScript
1
2
1
self.label["text"] = "Total tries: 0",
2
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.