小编Ama*_*zon的帖子

为什么我在标签小部件中的文本周围会出现难看的花括号? - Tkinter

我在标签小部件的文本周围得到了大括号.输出{Total tries: 0}代替Total tries: 0.

这是我的代码的简短版本:

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()
Run Code Online (Sandbox Code Playgroud)

python tkinter curly-brackets

4
推荐指数
1
解决办法
3238
查看次数

AttributeError:“按钮”对象没有属性“设置”-tkinter

我收到一个错误:

self.button.set(str(self))
AttributeError: 'Button' object has no attribute 'set'
Run Code Online (Sandbox Code Playgroud)

我不知道要进行哪些更改才能使其正常工作。

这是代码的重要部分:

class Cell:
    def show_word(self):
            """ Shows the word behind the cell """
            if self.hidden == True:
                self.hidden = False
            else:
                self.hidden = True

            self.button.set(str(self))

class Memory(Frame):
    def create_widgets(self):
        """ Create widgets to display the Memory game """
        # instruction text
        Label(self,
              text = "- The Memory Game -",
              font = ("Helvetica", 12, "bold"),
              ).grid(row = 0, column = 0, columnspan = 7)

        # buttons to show the words
        column …
Run Code Online (Sandbox Code Playgroud)

tkinter attributeerror

1
推荐指数
1
解决办法
4909
查看次数

标签 统计

tkinter ×2

attributeerror ×1

curly-brackets ×1

python ×1