3 Replies - 458 Views - Last Post: 06 May 2013 - 05:37 PM Rate Topic: -----

#1 snow_ninja67  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3485
  • View blog
  • Posts: 11,891
  • 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

Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3485
  • View blog
  • Posts: 11,891
  • 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

Was This Post Helpful? 1
  • +
  • -

#4 snow_ninja67  Icon User is offline

  • New D.I.C Head

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

Re: my onkey function is not working.

Posted 06 May 2013 - 05:37 PM

View Postandrewsw, 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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1