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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.