Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

class Cell:
    def check(self):
        mem.tries += 1
        mem.update_tries()

class Memory(Frame):
    def __init__(self, master):
        super(Memory, self).__init__(master)
        self.grid()
        self.create_widgets()
        self.tries = 0

    def create_widgets(self):
        self.label = Label(self)
        self.label["text"] = "Total tries: 0",
        self.label["font"] = ("Helvetica", 11, "italic")
        self.label.grid(row = 7, columnspan = 7, pady = 5)

    def update_tries(self):
        self.label["text"] = "Total tries: " + str(self.tries)

root = Tk()
root.title("Memory")
root.geometry("365x355")
mem = Memory(root)
root.mainloop()
like image 972
Amazon Avatar asked Nov 28 '11 21:11

Amazon


1 Answers

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.

like image 128
Felix Loether Avatar answered Sep 27 '22 19:09

Felix Loether