turtle-graphics

adding an image to the Turtle Screen

余生颓废 提交于 2019-11-28 04:55:39
问题 How can I add image to my Turtle Screen using turtle graphics? whenever I use the function addshape I keep getting errors. does turtle graphics got any other way loading/importing images? for example: import turtle screen = turtle.Screen() image = r"C:\Users\myUser\Desktop\Python\rocketship.png" screen.addshape(image) turtle.shape(image) 回答1: The turtle module does have support for images, but only GIF images, not PNG or any other format. As the docs for addshape say: name is the name of a

Python 3.0 using turtle.onclick

不羁岁月 提交于 2019-11-28 02:22:21
So here is my problem, I have to make a picture for my CS class and it is really frustrating estimating in turtle. I planed to use .onclick() to show me to position. import turtle as t def getPos(x,y): print("(", x, "," ,y,")") return def main(): t.onclick(getPos) t.mainloop() main() The turtle documentation seems to say that the onclick will pass the coordinates in a function that takes in two variables. http://docs.python.org/3.1/library/turtle.html#turtle.onclick NOTE: It works when I click on the arrow head, but thats not what I want. I want to click some other position on the screen to

Can't import turtle module in Python 2.x and Python 3.x

半城伤御伤魂 提交于 2019-11-27 18:12:09
问题 I want to play with turtle module in Python. But when i do import turtle module, i've the following error: $ python Python 2.7.3 (default, Sep 26 2012, 21:51:14) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import turtle Traceback (most recent call last): File "<stdin>", line 1, in <module> File "turtle.py", line 3, in <module> myTurtle = turtle.Turtle() AttributeError: 'module' object has no attribute 'Turtle' and for Python 3.x: $ python3

Turtle graphics - How do I control when the window closes?

末鹿安然 提交于 2019-11-27 12:01:09
问题 I have a small python script which draws some turtle graphics. When my script has finished running, the turtle screen automatically closes, so to be able to see the graphics for a while I have to use time.sleep(5) at the end of the script to delay the closing. Is there any way I can make this more dynamic, i.e. tell python that I want to control the closing of the window myself? I don't mind if the script can't do anything else while waiting for my command, but I'd prefer if I didn't have to

Attribute Error: 'list' object has no attribute 'split'

风流意气都作罢 提交于 2019-11-27 11:37:11
I am trying read a file and split a cell in each line by a comma and then display only the first and the second cells which contain information regarding the latitude and the longitude. This is the file: time, latitude,longitude ,type2015-03-20T10:20:35.890Z, 38.8221664,-122.7649994 ,earthquake2015-03-20T10:18:13.070Z, 33.2073333,-116.6891667 ,earthquake2015-03-20T10:15:09.000Z, 62.242,-150.8769 ,earthquake My program: def getQuakeData(): filename = input("Please enter the quake file: ") readfile = open(filename, "r") readlines = readfile.readlines() Type = readlines.split(",") x = Type[1] y =

Turtle in python- Trying to get the turtle to move to the mouse click position and print its coordinates

人走茶凉 提交于 2019-11-27 08:10:34
问题 I'm trying to get the mouse position through Python turtle. Everything works except that I cannot get the turtle to jump to the position of the mouse click. import turtle def startmap(): #the next methods pertain to drawing the map screen.bgcolor("#101010") screen.title("Welcome, Commadore.") screen.setup(1000,600,1,-1) screen.setworldcoordinates(0,600,1000,0) drawcontinents() #draws a bunch of stuff, works as it should but not really important to the question turtle.pu() turtle.onclick

Detecting collision in Python turtle game

走远了吗. 提交于 2019-11-27 07:19:05
问题 I am trying to make a Python game where the red turtle chases the blue turtle. When the red turtle catches the blue turtle, I want it to say 'COLLISION' on the screen but it is not working. When it collides, nothing happens and it gives me an error 'Turtle' object is not callable'. from turtle import Turtle, Screen playGround = Screen() playGround.screensize(250, 250) playGround.title("Turtle Keys") run = Turtle("turtle") run.speed("fastest") run.color("blue") run.penup() run.setposition(250,

Is there a way to save turtle's drawing as an animated GIF?

99封情书 提交于 2019-11-27 07:17:58
问题 I like what the turtle module does in Python and I'd like to output the entire animation of it drawing the shape. Is there a way to do this? GIF/MP4/anything that shows the animation. Note, I know that an external screen recorder will do the job, but I'm looking for a way for the turtle module to do this itself. 回答1: Make an animated GIF from Python turtle using Preview on OSX 1) Start with a working program As obvious as that seems, don't be debugging your code while trying to generate the

Python 3.0 using turtle.onclick

a 夏天 提交于 2019-11-27 04:53:06
问题 So here is my problem, I have to make a picture for my CS class and it is really frustrating estimating in turtle. I planed to use .onclick() to show me to position. import turtle as t def getPos(x,y): print("(", x, "," ,y,")") return def main(): t.onclick(getPos) t.mainloop() main() The turtle documentation seems to say that the onclick will pass the coordinates in a function that takes in two variables. http://docs.python.org/3.1/library/turtle.html#turtle.onclick NOTE: It works when I

How to speed up python's 'turtle' function and stop it freezing at the end

岁酱吖の 提交于 2019-11-26 20:35:44
问题 I have written a turtle program in python, but there are two problems. It goes way too slow for larger numbers, I was wonder how I can speed up turtle. It freezes after it finishes and when clicked on, says 'not responding' This is my code so far: import turtle #Takes user input to decide how many squares are needed f=int(input("How many squares do you want?")) c=int(input("What colour would you like? red = 1, blue = 2 and green =3")) n=int(input("What background colour would you like? red =