How do I change a LabelNode overtime?
Hello all, I am fairly new to Python, as well as Pythonista. I wanted to know if there is a way to change a LabelNode text overtime using the scene timer. I tried executing my code in the update function but it just keeps overlapping tons of text instead of altering the existing one. What am I doing wrong?
from scene import * import sound import random import math A = Action class MyScene (Scene): def setup(self): self.clock = 0 self.background_color = 'black' self.label = LabelNode(str(self.clock), font=('Courier', 40), color='white', position=(self.size.w/2, self.size.h/2), parent=self) def update(self): self.clock += int(self.t) self.label = LabelNode(str(self.clock), font=('Courier', 40), color='white', position=(self.size.w/2, self.size.h/2), parent=self) if __name__ == '__main__': run(MyScene(), show_fps=False)```
cvp last edited by
def update(self): self.clock += int(self.t) self.label.text = str(self.clock)
@cvp Thanks so much it worked perfectly! I don’t know why I didn’t think of modifying the text attribute.
Hey @cvp, would you care to help me again lol? I tried to demo a loading bar using a ShapeNode class. I used self.w as a variable for the width but it won’t update its width when I run the code.
from scene import * import scene import ui class load_bar(scene.ShapeNode): def __init__(self, **kwargs): self.w = 0 super().__init__(path=ui.Path.rect(0,0,self.w,5), fill_color='white', stroke_color=None, shadow=None, **kwargs) class MyScene (Scene): def setup(self): self.background_color = 'grey' self.load = load_bar(position=(200,200), parent=self) self.load.anchor_point = (0,0) self.load.w = 0 def update(self): while self.load.w < 100.0: self.load.w += 1 if __name__ == '__main__': run(MyScene(), show_fps=False)```
cvp last edited by cvp
@ccb_2k18 sorry to answer so late but there is a time zone difference😇
I've seen you posted the same question in another topic and you are right.
Don't ask a question to only one person, and surely me, there are in this forum a lot of marvelous people, and often a lot smarter than me.