Simple turtle graphic programme, what's wrong?

  • Context: Python 
  • Thread starter Thread starter ChloeYip
  • Start date Start date
  • Tags Tags
    Graphic
Click For Summary

Discussion Overview

The discussion revolves around a Python turtle graphics program intended to make a turtle disappear upon clicking it. Participants explore issues related to the program's functionality, code structure, and the requirements for using the turtle graphics library.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Exploratory

Main Points Raised

  • One participant expresses confusion about why the turtle does not disappear when clicked, despite no error messages being generated.
  • Another participant suggests that the turtle must first be created using turtle.Turtle() before it can be hidden.
  • Documentation is referenced, indicating that the function passed to onclick should accept two parameters for the click coordinates.
  • Some participants discuss whether the existing turtle instance is sufficient or if a new one needs to be created.
  • A participant proposes modifying the hide function to accept the coordinates, but notes that these parameters may not need to be used within the function.
  • Another participant confirms that the function should indeed take the parameters, but does not clarify if this resolves the issue.
  • There are repeated assertions that the turtle does not respond to clicks, prompting questions about additional code that may be present.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the exact cause of the issue, with multiple viewpoints on whether the existing code is sufficient or if additional modifications are necessary. The discussion remains unresolved regarding the effectiveness of the proposed solutions.

Contextual Notes

There is uncertainty about the necessity of creating a new turtle instance and whether the function's parameters are required for the intended functionality. The discussion also highlights potential gaps in the participants' understanding of the turtle graphics library.

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:
Technology 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...
 
  • #10
ChloeYip said:
The turtle doesn't response when i click on it...
Do you have any more code than what you show in this thread?

All you're doing in the code here is hiding the turtle. Have you looked at the documentation for turtle graphics? If not, follow this link: https://docs.python.org/3/library/frameworks.html
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
Replies
2
Views
2K
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
3
Views
3K
Replies
55
Views
7K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K