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.


    Time.sleep() for ui?

    Pythonista
    time timer ui.view
    4
    7
    6121
    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.
    • Bjucha
      Bjucha last edited by

      Hello everybody, trying to create a simple timer that counts down from 10 to 0.
      Creating one in that executes in console is no problem when using time.sleep function and a simple while condition, but for the ui if using a time.sleepfunction everything freezes. Read someware that time.sleep does not work for the ui. Is that correct? And if so what should I use instead?

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

        omz-software.com/pythonista/docs/ios/ui.html#ui.delay

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

          @ccc thx!

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

            Hmm wrote it like this

            import time, ui
            
            timme = 30
            
            def CountDown(sender):
            	global timme
            	
            	if timme > 0:
            		label1.text = str(timme)
            		ui.delay(sender.CountDown, 1)
            		timme = timme - 1
            		label1.text = str(timme)
            

            but now I get "Attribute error" ui.Button has no attribute 'CountDown' and it refering to the

            ui.delay(sender.CountDown, 1)
            

            line. Tried different combinations for the ui.delay but will always get this error. What am I missing?

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

              In the line that is failing, sender is a ui.Button but you have defined CountDown as a standalone function, not as a method of ui.Button().

              Try CountDown(sender) instead of sender.CountDown()

              Also code format requires the three backticks are on a line by themselves with no other text before or after them on the same line.

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

                This post is deleted!
                1 Reply Last reply Reply Quote 0
                • hanfuontod
                  hanfuontod last edited by

                  This post is deleted!
                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Powered by NodeBB Forums | Contributors