Search code examples
pythonvpython

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?


Solution

  • 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)