How to stop turtle from drawing even with pen up?

烈酒焚心 提交于 2019-12-06 13:33:56

问题


I am using the turtle module in python. the problem is that whenever I have the turtle move i will draw even if the pen is up. for example if I run this program:

import turtle

turtle.penup
turtle.goto(0,50)

the turtle will still draw a line when it moves to (0,50) why is this and how can it be prevented?


回答1:


It looks like you're not actually calling turtle.penup. Try this:

import turtle

turtle.penup()
turtle.goto(0,50)



回答2:


You have a typo, you aren't calling the penup method:

import turtle

turtle.penup() #This needs to be a method call
turtle.goto(0,50)



回答3:


This question is super old and definitely has already been answered, but I'll leave this explanation here for future people

"penup" is a method in Python, aka function in other languages. This means that when you want to use it you have it include some parenthesis just so that your code knows what is supposed to be happening

import turtle

turtle.penup()
turtle.goto(0,50)

When you don't include the parenthesis, the code thinks you are talking about a variable, and looks for one called "penup", but there is no variable of that name, so Python throws its hands up and crashes




回答4:


import turtle

turtle.up() turtle.goto(0,50) turtle.down()

if you don't put the pen down it will keep on drawing in invisible condition.




回答5:


you called penup without (). with

turtle.penup()

this will work.

Others here said that, but implicitly. trying to ensure it is clear where the typo is.




回答6:


no it should be something like this:

turtle.up()         # This a method call
turtle.goto(0,50)   # Part of the method call


来源:https://stackoverflow.com/questions/15602192/how-to-stop-turtle-from-drawing-even-with-pen-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!