vossmalte
vossmalte

Reputation: 184

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?

Upvotes: 0

Views: 1255

Answers (2)

network_freaksme
network_freaksme

Reputation: 21

It should be something like this

def scoring(self):
    self.score=self.score+1
    self.counter.text = str(self.score)
    print (self.score)

Upvotes: 1

Martijn Pieters
Martijn Pieters

Reputation: 1121306

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)

Upvotes: 3

Related Questions