omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    How do I change a LabelNode overtime?

    Pythonista
    timer clock animation scene text
    2
    5
    3094
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ccb_2k18
      ccb_2k18 last edited by

      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 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @ccb_2k18 last edited by

        @ccb_2k18 try

            def update(self):
                self.clock += int(self.t)
                self.label.text = str(self.clock)
        
        1 Reply Last reply Reply Quote 1
        • ccb_2k18
          ccb_2k18 last edited by

          @cvp Thanks so much it worked perfectly! I don’t know why I didn’t think of modifying the text attribute.

          1 Reply Last reply Reply Quote 0
          • ccb_2k18
            ccb_2k18 last edited by

            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 1 Reply Last reply Reply Quote 0
            • cvp
              cvp @ccb_2k18 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.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Powered by NodeBB Forums | Contributors