Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Turtle onkey()
#11
The following binds every keypress directly to the canvas as a tkinter bind, not a turtle bind.
import turtle


def key_handler(event):
    print(event.char)


window = turtle.Screen()
window.cv.bind('<KeyPress>', key_handler)
window.listen()
window.mainloop()

Tried it in trinket, doesn't work.
Error:
AttributeError: 'Screen' object has no attribute 'cv' on line 11 in main.py
Reply
#12
Thanks Yoriz. I get frustrated by the trinket version of Turtle all the time.
Reply
#13
Finally solved by making a list of functions and using an inner function to create the onkey functions for each letter.

trinket

It seems trinket turtles only recognise onkey() for lower case letters and digits 0-9.

Thanks for the help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  wn = turtle.screen() AttributeError: module 'turtle' has no attribute 'screen' Shadower 1 6,171 Feb-06-2019, 01:25 AM
Last Post: woooee
  t.onkey command isn't working PythonSnake 2 3,047 Jan-24-2019, 08:02 PM
Last Post: PythonSnake
  Help! Turtle not working, even when we click the turtle demo in IDLE nothing happens. BertyBee 3 5,622 Jan-04-2019, 02:44 AM
Last Post: SheeppOSU

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020