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.


    Bug: onkeypress

    Pythonista
    3
    5
    193
    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.
    • R
      ramorez last edited by

      onkey and onkeypress generated errors in pythonista.

      AttributeError:
      'TurtleView' object has no attribute 'onkeypress ' 'onkey'

      This code works in other python IDE environments verbatim (such as PyCharm / Replit).

      code:

      import turtle

      window = turtle.Screen()
      fred = turtle.Turtle()

      def draw_square():
      for _ in range(4):
      fred.forward(100)
      fred.left(90)

      window.onkeypress(draw_square, 'space')
      window.listen()

      turtle.done()

      JonB 1 Reply Last reply Reply Quote 0
      • JonB
        JonB @ramorez last edited by

        @ramorez In pythonista, turtle doesn't run via tkinter, but the pythonista UI environment. So you can't use all of the same features. You would need to add your own functionality via pythonista UI module.

        1 Reply Last reply Reply Quote 0
        • R
          ramorez last edited by

          @JonB hi! thank you. no idea about that so will have a look.

          cvp 1 Reply Last reply Reply Quote 0
          • cvp
            cvp @ramorez last edited by

            @ramorez try this quick and dirty script to understand that ui allows you to intercept touch and turtle do draw in another tab, at console side

            import turtle
            import ui
            
            fred = turtle.Turtle()
            
            def draw_square():
            	for _ in range(4):
            		fred.forward(100)
            		fred.left(90)
            					
            class MyView(ui.View):
            	def __init__(self,*args, **kwargs):
            		ui.View.__init__(self,*args,**kwargs)
            		self.background_color = 'white'
            		self.name = 'tap anywhere under this titlebar to start turtle'
            		
            	def touch_began(self, sender):
            		draw_square()
            		self.close()
            		
            v = MyView()
            v.present('fullscreen')
            
            R 1 Reply Last reply Reply Quote 0
            • R
              ramorez @cvp last edited by

              @cvp thank you. I will check it out.

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