turtle-graphics

How to close the Python turtle window after it does its code?

别等时光非礼了梦想. 提交于 2019-12-05 02:07:12
I'm working on a simple program in Python 3.5 that contains turtle graphics and I have a problem: after the turtle work is finished the user has to close the window manually. Is there any way to program the window to close after the turtle work is done? Any help is appreciated. turtle.bye() , aka turtle.Screen().bye() , closes a turtle graphics window. Usually, a lack of turtle.mainloop() , or one of its variants, will cause the window to close because the program will exit, closing everything. turtle.mainloop() should be the last statement executed in a turtle graphics program unless the

How to draw a checkered flag to the Python screen?

可紊 提交于 2019-12-04 22:10:55
QUESTION: Implement the following pseudocode to draw a checkered flag to the screen. 1. Ask the user for the size of the checkered flag (n). 2. Draw an n x n grid to the screen. 3. For i = 0,2,4,...,62: 4. row = i // n 5. offset = row % 2 6. col = (i % n) + offset Please copy and paste the link see the ouput: http://www.awesomescreenshot.com/image/45977/12eaef67de44c2b291ecd47fe8d10135 I implemented the pseudocode, but I need some help. I am keep getting this error: row, col = findGrid(x) TypeError: 'int' object is not iterable My program: from turtle import* def size(): size = eval(input(

How to stop turtle from drawing even with pen up?

若如初见. 提交于 2019-12-04 19:25:26
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? It looks like you're not actually calling turtle.penup. Try this: import turtle turtle.penup() turtle.goto(0,50) 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) This question is super old and definitely has

Python - Move Two Turtle Objects At Once

别来无恙 提交于 2019-12-04 18:24:39
I would like to create a program where one turtle object moves to where a user clicks their mouse, and a different turtle object moves at the same time. I have the first part, but I can't seem to get the rest to work. Any help would be appreciated. This is my code. (Credit for the first part of this goes to @Cygwinnian) from turtle import * turtle = Turtle() screen = Screen() screen.onscreenclick(turtle.goto) turtle.getscreen()._root.mainloop() turtle2 = Turtle() while True: turtle2.back(100) turtle2.forward(200) turtle2.back(100) I am by no means an expert at Python's turtle module, but here

Logic error in python turtle

牧云@^-^@ 提交于 2019-12-04 05:27:27
问题 I am coding in python 3.2 turtle and I have this beautiful drawing of a tank. and I know how to move it left and write. However, when trying to make the tank move up and down. I am faced with the problem that it goes up but if I let go and press the up button again. It turns to the left. It might be hard to explain so I included code. """ Programmer: Bert Tank Run 1 """ #------------------------------------------------------------------------------ #Importing random modules geddit from turtle

How can I make Turtle recognize a circle?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 05:22:43
问题 I am trying to make a Python program with Turtle Graphics that draws 2 circles overlapping (like a Venn Diagram) within a rectangle, and plots random dots onto the Venn Diagram. I have successfully done this, but now I want to make the program recognize if a point is in one of the circles or in the intersection of the Venn Diagram. I then want to change the color of the dots depending on which region they're in. What I have done so far for the program is listed variables, defined the shapes

Turtle graphics drawing over itself

拥有回忆 提交于 2019-12-04 05:16:09
问题 This should be a very simple question, however, it is proving difficult for me. I'm rather new to turtle graphics, and so, I am trying to get a simple drawing done. My turtle will draw a row, pick the pen up, move up one pixel, place the pen down, and keep drawing. Here's my code so far: for y in range(height): turtle.pendown() for x in range(width): detLand(y, x) # Set the color, works just fine turtle.setx(x) turtle.sety(y) turtle.penup() I figured this would be easy, however, it's still

TurtleGraphics Python: Bouncing turtle off the walls?

泪湿孤枕 提交于 2019-12-04 05:01:18
问题 So, I am trying to make a realistic bouncing function, where the turtle hits a wall and bounces off at the corresponding angle. My code looks like this: def bounce(num_steps, step_size, initial_heading): turtle.reset() top = turtle.window_height()/2 bottom = -top right = turtle.window_width()/2 left = -right turtle.left(initial_heading) for step in range(num_steps): turtle.forward(step_size) x, y = turtle.position() if left <= x <= right and bottom <= y <= top: pass else: turtle.left(180-2 *

Python turtle module causes OS X to crash

删除回忆录丶 提交于 2019-12-04 02:25:41
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. EDIT: When I run BenajahTX's suggestion below, I get this error message printed 16 times:

Python Turtle window with scrollbars

為{幸葍}努か 提交于 2019-12-03 08:25:20
I am new to Python, and have written a simple program in Python 2.7 using turtle graphics, which draws a fractal shape. The problem I have is that the turtle window doesn't have scrollbars, so if the shape is too large for the window, it is impossible to see all of it. Have googled but found no answer. Can anyone help? nixey26 Finally found some code at http://www.python-forum.de/viewtopic.php?f=1&t=24823&start=0 which provides a scrolled canvas for the turtle: import turtle import Tkinter as tkinter root = tkinter.Tk() root.geometry('500x500-5+40') #added by me cv = turtle.ScrolledCanvas(root