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.


    [RESOLVED!] Help with scene timing (short code)

    Pythonista
    2
    3
    1536
    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.
    • Pythonistapro777
      Pythonistapro777 last edited by

      How can I make desp (scene) be run 10 seconds after the first click of the button?

      Thanks in advance!

      Here's the code:
      <pre><code>
      import time
      from scene import *
      from PIL import Image
      clicks = 0
      class JitterClick(Scene):
      def setup(self):
      self.button = Button(Rect(self.size.w/2-100, self.size.h/2-140, 200, 200))
      self.button.background = Color(0,0,0)
      self.button.stroke = Color(0,0,0)
      self.button.image = 'Red_Circle'
      self.button.action = self.add_clicks
      self.add_layer(self.button)

      def add_clicks(sender):
      	global clicks
      	clicks += 1
      	
      def draw(self):
      	background(0,0,0)
      	self.button.background = Color(0,0,0)
      	self.button.draw()
      	text('Clicks: %i' % clicks, x=self.size.w/2, y=self.size.h/3.8*3, font_size=57)
      

      class desp(Scene):
      def setup(self):
      self.show_instructions = True
      self.p_size = 64 if self.size.w > 700 else 32

      def draw(self):
      	background(0, 0, 0)
      	speed=int(clicks)/10
      	text('In 10 seconds you managed to click %i times. At a speed of 5 clicks a second.' % clicks, x=self.size.w/2, y=self.size.h/3.8*3, font_size=57)
      

      run(JitterClick())
      </code></pre>

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

        In general, there is only supposed to be one scene.Scene in your app. It can be quite tricky to work around this limit but it can be done.

        You can search the forum for "multiscene" for one approach to getting around this limitation. You can see https://omz-forums.appspot.com/pythonista/post/5876387541942272 for a second approach.

        Are you better off using ui instead of scene or if you NEED a scene consider embedding it inside a ui.SceneView which will give you more flexibility. https://omz-forums.appspot.com/pythonista/post/5290516186923008

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

          Ok. I decided to do completely different, instead of making that I count the number of clicks in 10 seconds, I'll just record the time taken to do 100 clicks.
          Thanks for the help anyways @ccc

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