为什么在标签小部件中的文本周围出现丑陋的花括号? -Tkinter [英] Why am I getting ugly curly brackets around my text in the label widget? - Tkinter
本文介绍了为什么在标签小部件中的文本周围出现丑陋的花括号? -Tkinter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在标签小部件中的文本周围出现了大括号.输出是{Total tries: 0}
而不是Total tries: 0
.
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()
推荐答案
self.label["text"] = "Total tries: 0",
该行的末尾有一个逗号.逗号将分配给self.label["text"]
的值从字符串更改为元组.删除逗号,大括号被删除.
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.
这篇关于为什么在标签小部件中的文本周围出现丑陋的花括号? -Tkinter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文