# my onkey function is not working.

Page 1 of 1

## 3 Replies - 804 Views - Last Post: 06 May 2013 - 05:37 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=320436&amp;s=f6d7072f8b0b29cc2ac5bbef02f31e39&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 snow_ninja67

Reputation: 0
• Posts: 46
• Joined: 29-January 13

# my onkey function is not working.

Posted 06 May 2013 - 03:20 PM

Hello i have included 4 unkey functions within this code:

```from turtle import *

turtle_1 = Turtle()
turtle_2 = Turtle()
turtle_3 = Turtle()
turtle_4 = Turtle()
turtle_5 = Turtle()
turtle_6 = Turtle()
turtle_7 = Turtle()
def callback_1(x, y):
color("red")
shape("circle")
circle(100)

def callback_2(x, y):
color("blue")
shape("square")
circle(100, steps=4)

def callback_3(x, y): ## forward key ##
forward(100)
def callback_4(x, y):## Backward Key ##
forward(-100)
def callback_6(x, y):## makes the turte turn by 90 ##
right(90)
def callback_7(x, y):## makes the turte turn by -90 ##
right(-90)
def callback_5(x, y): ## reset ##
listen()
resetscreen()
place_turtles()

def place_turtles():
turtle_1.color("red")
turtle_1.shape("circle")
turtle_1.penup()
turtle_1.goto(-200, -200)
turtle_2.color("blue")
turtle_2.shape("square")
turtle_2.penup()
turtle_2.goto(0, -200)
turtle_3.color("red")
turtle_3.shape("arrow")
turtle_3.penup()
turtle_3.goto(150, -189)
turtle_3.right(-90)
turtle_4.shape("arrow")
turtle_4.color("red")
turtle_4.penup()
turtle_4.goto(150, -210)
turtle_4.right(90)
turtle_5.shape("square")
turtle_5.color("blue")
turtle_5.penup()
turtle_5.goto(150, -200)
turtle_5.write("Reset", align='right')
turtle_6.shape("arrow")
turtle_6.color("red")
turtle_6.penup()
turtle_6.goto(160, -200)
turtle_7.shape("arrow")
turtle_7.color("red")
turtle_7.penup()
turtle_7.goto(140, -200)
turtle_7.right(180)
listen()
onkey(callback_3, "Up")
onkey(callback_4, "Down")
onkey(callback_6, "Left")
onkey(callback_7, "Right")
place_turtles()
ondrag(goto)
screen=getscreen()
turtle_1.onclick(callback_1)
turtle_2.onclick(callback_2)
turtle_3.onclick(callback_3)
turtle_4.onclick(callback_4)
turtle_5.onclick(callback_5)
turtle_6.onclick(callback_6)
turtle_7.onclick(callback_7)
mainloop()

```

what the onkey functions are supposed to do is replace the onclick functions to make it easier to use but for some reason it gives me this error which i do not understand can someone explain it for me? and possibly show a way to make it work? Thanks!
Traceback (most recent call last):
File "C:\Python32\lib\tkinter\__init__.py", line 1399, in __call__
return self.func(*args)
File "C:\Python32\lib\turtle.py", line 686, in eventfun
fun()
TypeError: callback_6() takes exactly 2 arguments (0 given)

Is This A Good Question/Topic? 0

## Replies To: my onkey function is not working.

### #2 andrewsw

• I'm not here to twist your niblets

Reputation: 4109
• Posts: 14,841
• Joined: 12-December 12

## Re: my onkey function is not working.

Posted 06 May 2013 - 03:34 PM

It seems to be working for me; at least, there are no errors. What specific sequence of actions causes the error you received? Corrected: Oops, ignore me! I was using the mouse he, he. I'll try again.

However, there is some odd behaviour when dragging the arrow, particularly, it seems, if I overlap an existing line.

This post has been edited by andrewsw: 06 May 2013 - 03:40 PM

### #3 andrewsw

• I'm not here to twist your niblets

Reputation: 4109
• Posts: 14,841
• Joined: 12-December 12

## Re: my onkey function is not working.

Posted 06 May 2013 - 03:44 PM

The onkey event doesn't pass arguments - x, y are only supplied using the click event (or other mouse events). This makes sense, as x and y are mouse coordinates, which are not relevant when using the keyboard.

So, you can't use the same event handlers for both click and onkey.

This post has been edited by andrewsw: 06 May 2013 - 03:45 PM

### #4 snow_ninja67

Reputation: 0
• Posts: 46
• Joined: 29-January 13

## Re: my onkey function is not working.

Posted 06 May 2013 - 05:37 PM

andrewsw, on 06 May 2013 - 03:44 PM, said:

The onkey event doesn't pass arguments - x, y are only supplied using the click event (or other mouse events). This makes sense, as x and y are mouse coordinates, which are not relevant when using the keyboard.

So, you can't use the same event handlers for both click and onkey.

ahhhh okay so basically i derped because i had the other version with the mouse also the thing about it being glichy i do not know on how to fix it D: and sorry for the late response if you know how to fix that weird glitch please teach meh ;p

This post has been edited by snow_ninja67: 06 May 2013 - 05:38 PM