turtle-graphics

Using turtle module exitonclick()

最后都变了- 提交于 2019-12-12 06:31:51
问题 My code should close the turtle.screen after first part then start another screen and do the second part. but there it is not working as intend. import turtle ws = turtle.Screen() tod_1 = turtle.Turtle() tod_1.color("red", "green") tod_1.begin_fill() for i in range(3): tod_1.forward(50) tod_1.left(360 / 3) tod_1.end_fill() ws.exitonclick() input("go'press any thing' ") ws = turtle.Screen() tod_2 = turtle.Turtle() tod_2.color("red", "green") tod_2.begin_fill() for i in range(6): tod_2.forward

Move python turtle with mouse pointer

这一生的挚爱 提交于 2019-12-12 05:58:54
问题 I have been trying to save images capturing handwritten text for my handwritten text recognition project. For this purpose I am using the python turtle. I want to change the coordinates of the turtle (in pen up position) on the canvas by moving my mouse, and make it write (in pen down position) by moving the mouse while holding on the left mouse button. I am not able to implement this. Here is my code. import tkinter import turtle sc = tkinter.Tk() sc.geometry("1000x1000+100+100") fr4 =

TurtleGraphics Python - Constraining random-moving turtle in a circle?

好久不见. 提交于 2019-12-12 04:26:17
问题 How would I be able to make a randomly moving turtle be constrained inside a circle with a radius of 50, the circles center being at (0, 0)? So if the turtle is currently at location (x, y), it's distance from the center is math.sqrt(x ** 2 + y ** 2). Whenever the turtle's distance from the center is more than 50, have it turn around and continue. I have gotten the code to work with the screen size, but where do I put math.sqrt(x ** 2 + y ** 2) to get it to be constrained in a circle? Here's

Python Turtle Wait for Click

拟墨画扇 提交于 2019-12-12 04:24:56
问题 I'd like to be able to pause and contemplate each step of this program, and move on to the next step by clicking the screen. Initially I tried adding a bunch of events, but then my brain kicked in and reminded me that this is not a procedural program and the first binding would remain the only one(!). Main program below, any help much appreciated. def tree(self, branchLen): if branchLen > 5: self.screen.onscreenclick(lambda x,y: self.t.forward(branchLen)) self.screen.onscreenclick(lambda x,y:

Python Turtle Positional Errors

这一生的挚爱 提交于 2019-12-12 02:59:39
问题 I've been trying to scale a Turtle drawing by a single axis and after some testing, I managed the following function: def DrawSquare(length=50.0, Yscale=2): setheading(0) for n in range(0,4): oldYcor = int(ycor()) oldPos = pos() penup() forward(length) newYcor = int(ycor()) print 'OldYcor = ', int(oldYcor) print 'NewYcor = ', int(newYcor) print '------' setpos(oldPos) pendown() if (oldYcor == newYcor): print 'dont scale' forward(length) elif (oldYcor != newYcor): print 'scale' forward(length

Turtle window exit errors

无人久伴 提交于 2019-12-12 02:46:09
问题 When I click out of my turtle window it spits 24 lines of errors to the shell. The error report ends with turtle.Terminator . turtle.Terminator is not an exception so I can't handle it with try-except . Is there a base class for all turtle exceptions so I can get rid of these errors? 回答1: You want to use the window's native close button (eg. the red X in OSX) to close the window while your turtle code is running. You end up with lots of error messages to the terminal. The following approach

I want to add a countdown timer to my program

泪湿孤枕 提交于 2019-12-12 02:37:33
问题 So I am making a game in Python, and I am almost done, though I am stumped. There are a few things I want: I want to make a 30 second timer. The player has 30 seconds to collect as many pellets as he/she can. Second, after the timer is complete, the turtle is not controllable anymore. What do I need to do to fix these? Screen setup import turtle import math import random #screen wn=turtle.Screen() wn.bgcolor("lightblue") speed=1 wn.tracer(2) #Score Variable score=0 #Turtle Player spaceship=

Implement Python tkinter zoom with turtle and single/double click

半世苍凉 提交于 2019-12-11 21:45:17
问题 I am trying to draw turtle in canvas and I am also trying to implement zoom in zoom out feature with single click and double click event. When I am not trying to implement tkinter the code works absolutely fine but when I am trying to perform zoom in zoom out feature, I am unable to execute it. I would greatly appreciate any suggestions or help. Here is my code: import turtle import tkinter as tk from tkinter import * root = tk.Tk() canvas = tk.Canvas(master = root, width = 2700, height =

Python3.2 How to keep turtle from going off the screen and when it does reset?

筅森魡賤 提交于 2019-12-11 21:21:35
问题 I am writing a simple project with pygame and turtle graphics. They aren't integrated together. I want it so that when my turtle moves off the screen it bounces off. I looked for a while I tried using answers from some other posts but I could't make it work. It needs to always move forward. I get this error when I run it. Traceback (most recent call last): File "F:\move.pyw", line 86, in <module> main.fd(2) File "C:\Python32\lib\turtle.py", line 1630, in forward self._go(distance) File "C:

Understanding Functions in Python

跟風遠走 提交于 2019-12-11 18:22:00
问题 I'm trying to use the Turtle module in Python to draw the American flag using separate functions, first I have draw_flag which calculates all the dimensions, and then draw_rectangle which actually draws the flag shape, then ill make draw_stars, etc, to draw the stars and lines. But, I am having a bit of trouble understanding on how functions work..here is my code so far: import turtle import time import random def draw_rectangle(length, height): turtle.up() x = length y = height turtle.begin