turtle-graphics

Python Turtle Module- Saving an image

倖福魔咒の 提交于 2019-12-18 12:08:23
问题 I would like to figure out how to save a bitmap or vector graphics image after creating a drawing with python's turtle module. After a bit of googling I can't find an easy answer. I did find a module called canvas2svg, but I'm very new to python and I don't know how to install the module. Is there some built in way to save images of the turtle canvas? If not where do I put custom modules for python on an Ubuntu machine? 回答1: from Tkinter import * from turtle import * import turtle forward(100

How to change size of turtle?

不问归期 提交于 2019-12-18 09:29:23
问题 I am trying to double the size of the turtle in the window every time I press x on my keyboard. I tried using .turtlesize(2,2,2) , but that's not right. I need to double every time the key is pressed so if the turtle size is (1,1,1) , it will become (2,2,2) then (4,4,4) and so on each time I press x . This is what I have so far: import turtle turtle.setup(500,500) wn = turtle.Screen() wn.title("Commands") wn.bgcolor("black") tess = turtle.Turtle() tess.shape("triangle") tess.color("red") tess

Python imaging, resize Turtle Graphics window

风流意气都作罢 提交于 2019-12-18 08:49:00
问题 My image is too large for the turtle window. I had to enlarge the image because the text I need at each spot overlaps. How do I Resize the window in python? 回答1: It sounds like you have drawn an image, but it has gone outside the borders of the window, so therefore you need to make the window larger to see the entire image. To resize the window: setup( width = 200, height = 200, startx = None, starty = None) This will make your output window 200X200 (which may be too small for you so you'll

Is there a complete list of key event names used by turtle-graphics?

社会主义新天地 提交于 2019-12-14 01:50:34
问题 While playing around with Python's Turtle module, I used some key events as the official documentation states: turtle.onkey(fun, key) Parameters: fun – a function with no arguments or None key – a string: key (e.g. “a”) or key-symbol (e.g. “space”) Now the interesting thing is that when you call 1) the onkeyrelease() method and pass a not registered string (like an empty one ( "" ), or "+" , etc.) as key parameter: turtle.onkeyrelease(lambda: print("Got key event while listening to none."), "

“Stop” Button in Tkinter

孤人 提交于 2019-12-13 22:55:54
问题 I'm trying to have a turtle animation start with a button and stop with a button. It's very easy to start with a button but I can't seem to be able to figure out a stop button? Here's my code so far: import turtle import tkinter as tk def start(): t.forward(100) t.right(90) t.forward(100) t.left(90) t.forward(100) t.right(90) t.forward(100) t.right(90) t.forward(100) def stop(): t.stop def clear(): canvas.delete("all") root = tk.Tk() canvas = tk.Canvas(width = 500, height = 500) canvas.pack()

Python turtle module causes OS X to crash

巧了我就是萌 提交于 2019-12-13 11:59:03
问题 I'm working through Think Python chapter 4, where they tell you to type the following to see if you have the turtle module: import turtle bob = turtle.Turtle() This is supposed to open a new window, but instead, it crashes my computer. I've seen it freeze my computer where I can't move the cursor or change windows, and I have to restart it. And I've also seen it close all my programs and re-open them. I'm running Python 3.7 downloaded from Anaconda on a Macbook Air with Mojave version 10.14.6

Problems prompting user for input in Python

萝らか妹 提交于 2019-12-13 09:48:14
问题 import sys import turtle t=turtle.Pen def what_to_draw(): print ("What to do you want to see a sketch of that may or may not be colored?") what_to_draw=sys.stdin.readline() if what_to_draw=="flower/n": t.forward(90) elif(): print ("What you typed isn't in the code. Try putting a letter or letters to lowercase or uppercase. If that doesn't work, what you typed has not been set to make something happen") I typed in this code above. It says in the python shell "flower" isn't defined. Can someone

How to make python text into a button in python turtle?

元气小坏坏 提交于 2019-12-13 09:01:34
问题 I want to make the word "CAT" into a button, so when it's clicked it says "CAT". Also, the button I want should be in the position that the word is right now when it's not a button. Any help provided is needed. Thank you I have already tried the tkinter module, but the problem with that is it opens a separate window with the button. What I want is a button on the main screen. import turtle screen = turtle.Screen() # this assures that the size of the screen will always be 400x400 ... screen

How to send turtle to random position?

。_饼干妹妹 提交于 2019-12-13 08:35:32
问题 I have been trying to use goto() to send turtles to a random position but I get an error when running the program. I am lost on how else to do this and not sure of other ways. My current code is: t1.shape('turtle') t1.penup() t1.goto((randint(-100,0)),(randint(100,0)))#this is the line with the error I want the turtle to go to random coordinates in a box between -100,100 and 0,100 but I get the error: Traceback (most recent call last): File "C:\Users\samdu_000\OneDrive\Documents\python\battle

Python: how to make a turtle never cross over a line

为君一笑 提交于 2019-12-13 07:23:48
问题 I'm trying to write a python program that will make a turtle either move forward, turn left and then move, or turn right and then move randomly without ever crossing over its own previously drawn lines. It must stay within the screen and clear and restart once it has done the most possible moves. This is as far as I got: import turtle positions=[] while 'x': count=132 for x in range (132): count-=1 print(count) move = randint(1,3) if move == 1: turtle.fd(50) if move == 2: turtle.rt(90) turtle