实际上,我已经创建了一个简单的数学游戏,并显示问题是对还是错,但我无法得到更新的分数,也有人知道如何让问题刷新到另一个问题,我试过app.update?:
self.a1button = Tkinter.Button(self, background="blue",foreground="white", text = (random_row.A1), command = self.QUESTION1)
self.a1button.grid(row = 9, column = 1, sticky = 'W')
self.label5 = Tkinter.Label(self, text = "Score:")
self.label5.grid(row = 14, column = 1, columnspan = 5, sticky = 'S')
self.label7 = Tkinter.Label(self, text = 0 )
self.label7.grid(row = 14, column = 6, columnspan = 1, sticky = 'E')
def QUESTION1(self):
if self.a1button['text'] == self.label6['text']:
tkMessageBox.showinfo("CORRECT", "WELL DONE")
label7 = +100
app.refresh
else:
tkMessageBox.showinfo("INCORRECT", "YOU FULLY GOT IT WRONG :/")
label7 = -100
app.refresh
答案 0 :(得分:2)
您需要首先读取标签上的当前分数,添加或减去100分,然后再次设置标签:
score = int(self.label7.get())
score += 100
self.label7.set(str(score))
app.refresh()
请注意,您还需要调用 refresh
方法,而不仅仅是引用它。
使用 - =减去。