我希望分数显示在画布上,但到目前为止无济于事。我以为我可以使用:
self.canvas.create_text(200, 60, fill="darkblue", font="Times 15 italic bold", text="Your score is:",self.score)
不幸的是没有工作,那么我如何让分数显示在画布上?还想知道如何让一个消息框弹出“你赢了!” 当分数 = 10 时。最后,如何让一个消息框弹出“如果分数 < 10 并且画布上没有偶数,您就输了。
到目前为止使用 python 3.3 的代码:
def click(self, event):
if self.canvas.find_withtag(CURRENT):
item_uid = event.widget.find_closest(event.x, event.y)[0]
is_even = False
try: # clicked oval
self.bubbles[item_uid]
except KeyError: # clicked the text
for key, value in self.bubbles.iteritems():
if item_uid == value[5]: # comparing to text_id
if value[4] % 2 == 0:
is_even = True
self.canvas.delete(key) # deleting oval
self.canvas.delete(item_uid) # deleting text
else:
if self.bubbles[item_uid][4] % 2 == 0:
is_even = True
self.canvas.delete(item_uid) # deleting oval
self.canvas.delete(self.bubbles[item_uid][5]) # deleting text
if is_even:
self.score += 1
else:
self.score -= 1
if self.score == 10:
print ("You won")
print (self.score)