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
-
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()
-
@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.
-
@JonB hi! thank you. no idea about that so will have a look.
-
@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')