[英]How to display a score in Vpython?
My Code 我的密码
from visual import *
class Punktecounter():
def __init__(self,position=(0,0), score=0):
self.counter = label(pos=position, color=color.red, text=str(score))
self.score = score
def scoring(self):
self.score = self.score+1
print (self.score)
p = Punktecounter()
while True:
p.scoring()
rate(1)
So the printing part works fine. 因此打印部分工作正常。 But the label doesn't show the score.
但是标签没有显示分数。 How to fix that?
如何解决?
The label is not going to update itself, you need to do so explicitly: 标签不会自行更新,您需要明确地进行更新:
def scoring(self):
self.score=self.score+1
self.label.text = str(self.score)
print (self.score)
It should be something like this 应该是这样的
def scoring(self):
self.score=self.score+1
self.counter.text = str(self.score)
print (self.score)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.