turtle-graphics

Python - Make One Turtle Object Always Above Another

半世苍凉 提交于 2019-12-02 18:04:34
问题 I would like to create a program where one Turtle object always stays above all of the other Turtle objects. I don't know if this is possible, but any help would be apprecated. This is my code: from turtle import * while True: tri = Turtle() turtle = Turtle() tri.pu() tri.pencolor("white") tri.color("black") tri.shape("turtle") tri.bk(400) turtle = Turtle() turtle.pu() turtle.pencolor("white") turtle.shape("square") turtle.color("white") turtle.pu() turtle.speed(0) tri.speed(0) turtle

How do I get the X coordinate for my turtle graphics turtle

懵懂的女人 提交于 2019-12-02 17:17:20
问题 I can create a turtle that will be in a window with the following code: Turtle t1 = new Turtle(w,100,100); If I want to know its coordinates, I can write: int getX(w); But when I have 2 turtles, t1 and t2, I don't know what to do if I want to know turtle1's X coordinates. Turtle t1 = new Turtle(w,100,100); Turtle t2 = new Turtle(w,200,100); If I were to write int getX(w) , which turtles X coordinate would I get? How do I write so I get t1 s cordinate? 回答1: I have no idea what Turtle class you

ImportError: No module named Tkinter when importing swampy.TurtleWorld

百般思念 提交于 2019-12-02 16:02:32
问题 I am using Python 3.4 and following along the book "Think Python: how to think like a computer scientist". I actually figured out this issue a week ago, but saved over the original code when it failed to run like it did last week. Right now I have: import tkinter from swampy.TurtleWorld import * which yields: ImportError: No module named 'Tkinter' When I had the code working last week, I loosely recall that in the 'import tkinter' line, there was a portion at the end that looked like this:

Is there any way to resize a gif shape with turtle in Python?

寵の児 提交于 2019-12-02 13:51:48
问题 I'm using turtle to make a little game and realized I could use image files with turtle.registershape(filename) . I know you can resize the default shapes with turtle.shapesize or turtle.resizemode("auto") and changing pensize , but is there any way to resize a gif file using these methods? import turtle turtle.addshape("example.gif") t = turtle.Turtle() t.shape("example.gif") t.resizemode("auto") t.pensize(24) t.stamp() turtle.exitonclick() I want something like this to work, but the turtle

How to make the turtle follow the mouse in Python 3.6

感情迁移 提交于 2019-12-02 11:53:22
问题 I'm assigned to create a similar version of slither.io in python. I planned on using Turtle . How do I make the turtle follow my mouse without having to click every time? This is how I would do it when clicking, but I would rather not have to click: from turtle import * turtle = Turtle() screen = Screen() screen.onscreenclick(turtle.goto) turtle.getscreen()._root.mainloop() 回答1: The key to it is to use the ondrag() event handler on a turtle. A short and not so sweet solution: import turtle

How Do You Make Python Turtle Stop Moving?

谁都会走 提交于 2019-12-02 11:21:22
问题 I've tried to do turtle.speed(0) , and I've tried turtle.goto(turtle.xcor(), turtle.ycor()) nothing is seeming to work. This Is The Code: import turtle def stopMovingTurtle(): ## Here I Need To Stop The Turtle ## turtle.listen() turtle.onkey(stopMovingTurtle, 'Return') turtle.goto(-200, 0) turtle.goto(200, 0) So how do I stop it? 回答1: The problem here isn't the order of turtle.listen() vs. turtle.onkey() , it's that the key event isn't being processed until the current operation completes.

Turtle Graphics - Extract Color from onscreenclick

谁都会走 提交于 2019-12-02 09:24:42
I am using Turtle Graphics in Python for a larger program. I am able to return the point that the user clicks on using turtle.onscreenclick However, I would like to extract the RGB color of the point that the user clicks on. Can this even be done in turtle graphics and how can this be accomplished? Thank you! import turtle # Global variables specifying the point clicked xclick = 0 yclick = 0 # Draw a rectangle that is red height = float(50) length = height *(1.9) length = round(length,2) turtle.begin_fill() turtle.color("red") turtle.down() turtle.forward(length) turtle.right(90) turtle

How to save animated GIF images drawing in Python turtle module?

别说谁变了你拦得住时间么 提交于 2019-12-02 08:35:25
I am new to Python turtle module, I wrote a very easy code, like, from turtle import * import turtle forward(100) right(90) forward(200) circle(10) ts = turtle.getscreen() turtle.getcanvas().postscript(file = "duck.eps") I got a .eps image, it looks well, but what I want is an animated image in .gif . However, when I try to say, turtle.getcanvas().postscript(file = "duck.gif") I got the duck.gif, but I cannot open it !! What should I do now? 来源: https://stackoverflow.com/questions/40650099/how-to-save-animated-gif-images-drawing-in-python-turtle-module

Python - Make One Turtle Object Always Above Another

…衆ロ難τιáo~ 提交于 2019-12-02 08:29:55
I would like to create a program where one Turtle object always stays above all of the other Turtle objects. I don't know if this is possible, but any help would be apprecated. This is my code: from turtle import * while True: tri = Turtle() turtle = Turtle() tri.pu() tri.pencolor("white") tri.color("black") tri.shape("turtle") tri.bk(400) turtle = Turtle() turtle.pu() turtle.pencolor("white") turtle.shape("square") turtle.color("white") turtle.pu() turtle.speed(0) tri.speed(0) turtle.shapesize(100,100,00) setheading(towards(turtle)) while tri.distance(turtle) > 10: turtle.ondrag(turtle.goto)

Reading two separate values in one line in python

我的未来我决定 提交于 2019-12-02 08:09:14
问题 I need your help. This is my program so far import turtle turtle.showturtle() def turtle_interface(): while True : n = 0 instructions = input().split() i = instructions[0] if len(instructions) > 1: n = int(instructions[1]) if i == 'forward' : turtle.forward(n) elif i == 'backward' : turtle.backward(n) elif i == 'left' : turtle.left(n) elif i == 'right' : turtle.right(n) elif i == 'quit' : break elif i == 'new' : turtle.reset() else : continue print('Control the turtle!') turtle_interface() As