Simple turtle graphic programme, what's wrong?

  • Context: Python 
  • Thread starter Thread starter ChloeYip
  • Start date Start date
  • Tags Tags
    Graphic
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
9 replies · 2K views
ChloeYip
Messages
93
Reaction score
1
I want to write a program when I click the turtle, the turtle would disappear.
However, the program does not gave error message but when I click the turtle, there is no effect on it.
What's wrong with it?
How can I fix it?
Thanks
Mod note: Added code tags.
My written programme:
Python:
import turtle
import pygame

def hide():
    turtle.hideturtle()
turtle.onclick(hide)
 
Last edited by a moderator:
Physics news on Phys.org
ChloeYip said:
I want to write a program when I click the turtle, the turtle would disappear.
However, the program does not gave error message but when I click the turtle, there is no effect on it.
What's wrong with it?
How can I fix it?
Thanks
Mod note: Added code tags.
My written programme:
Python:
import turtle
import pygame

def hide():
    turtle.hideturtle()
turtle.onclick(hide)
Please use code tags, especially with Python code!
They look like this
Python:
<your code>
I don't know anything about turtle graphics in Python, but I suspect if you want to hide the turtle, you first have to make it appear.Have you looked at any documentation for turtle graphics in Python? I did a web search for "python turtle" and found this as the first link: https://docs.python.org/2/library/turtle.html
 
ChloeYip said:
I want to write a program when I click the turtle, the turtle would disappear.
However, the program does not gave error message but when I click the turtle, there is no effect on it.
What's wrong with it?
How can I fix it?
Thanks
Mod note: Added code tags.
My written programme:
Python:
import turtle
import pygame

def hide():
    turtle.hideturtle()
turtle.onclick(hide)

According to the documentation the function which is given as argument to onclick should take two arguments representing the coordinates.
 
  • Like
Likes   Reactions: jedishrfu
jedishrfu said:
Here's a blog on turtle graphics

https://michael0x2a.com/blog/turtle-examples

Notice the very first thing is to create a turtle via turtle.Turtle()
There is already one turtle when import turtle. I don't think it is a problem if I do not create one more...

eys_physics said:
According to the documentation the function which is given as argument to onclick should take two arguments representing the coordinates.

Do you mean I should add a line like "x,y = turtle.pos()"? But I thought "turtle.onclick()" is meaning to click the turtle...
 
No, you don't need. But, your function hide should take to parameters (the coordinates). However, You don't need to do something with these parameters inside the function.
 
Python:
import turtle 
import pygame 
def hide(x,y):     
     turtle.hideturtle() 
turtle.onclick(hide)

Do you mean like this?
 
ChloeYip said:
Python:
import turtle
import pygame
def hide(x,y):    
     turtle.hideturtle()
turtle.onclick(hide)

Do you mean like this?

Yes. Does it help?
 
The turtle doesn't response when i click on it...