属性错误:“按钮”对象没有属性“set”; - tkinter
我收到错误:
self.button.set(str(self))
AttributeError: 'Button' object has no attribute 'set'
我不知道要更改什么才能使其正常工作。
这是代码的重要部分:
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 = 0
row = 1
the_pairs = self.readShuffle()
for index in range(36):
temp = Button(self,
text = the_pairs[index],
width = "7",
height = "2",
relief = GROOVE,
command = lambda x = index: Cell.show_word(the_pairs[x])
)
temp.grid(row = row, column = column, padx = 1, pady = 1)
column += 1
the_pairs[index].button = temp
if column == 6:
column = 0
row += 1
I'm getting an error:
self.button.set(str(self))
AttributeError: 'Button' object has no attribute 'set'
I can't figure out what to change to make it work.
Here is the important parts of the code:
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 = 0
row = 1
the_pairs = self.readShuffle()
for index in range(36):
temp = Button(self,
text = the_pairs[index],
width = "7",
height = "2",
relief = GROOVE,
command = lambda x = index: Cell.show_word(the_pairs[x])
)
temp.grid(row = row, column = column, padx = 1, pady = 1)
column += 1
the_pairs[index].button = temp
if column == 6:
column = 0
row += 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Button
没有set
属性。Tkinter 小部件属性使用这两种替代样式进行设置:
使用其中一种
Button
's have noset
attribute.Tkinter widget properties are set with these two alternative styles:
Use one of them