turtle-graphics

turtle.done() not working in Spyder

寵の児 提交于 2019-12-11 06:36:33
问题 This simple Python script: import turtle bob = turtle.Turtle() bob.forward(50) turtle.done() yields an error when running it using Spyder. The first run works as expected, but after that, the IPython console raises a "Terminator". The same happens when using turtle.exitonclick() instead of turtle.done() . What am I doing wrong? Note that running it from the CLI works fine. 回答1: I don't use Spyder but have exchanged comments with others who have similar problems running turtle in similar

Draw Letters In Turtle

别来无恙 提交于 2019-12-11 06:19:35
问题 I just started learning turtle in python. I am tried to write my name "Idan" (capital letters), but I am stuck on "D". This is my code so far: import turtle t = turtle.Turtle() t.up() t.backward(400) t.left(90) t.down() t.forward(250) t.right(90) t.forward(62.5) t.backward(62.5 * 2) t.forward(62.5) t.right(90) t.forward(250) t.right(90) t.forward(62.5) t.backward(62.5 * 2) t.up() t.backward(100) t.right(90) t.down() t.forward(250) for x in range(180): t.forward(1) t.right(1) But when I run it

How to output variable on turtle screen?

杀马特。学长 韩版系。学妹 提交于 2019-12-11 04:37:53
问题 I want to output a variable on the Turtle screen. But as the variable changes, the previous value is still on the screen. Thus, the values are overlapped. Method turtle.clear() does not solve the problem, because it causes the value to flicker on the screen. # -*- coding: utf-8 -*- import turtle from math import * s = turtle.Screen() body = turtle.Turtle() time_t = turtle.Turtle() time_t.penup() # For time output time_t.ht() def Motion(A=100, omega=5, N=2): n = 0 t = 0 def x_pos(t): return A

Getting Turtle to Bounce Off the Walls

被刻印的时光 ゝ 提交于 2019-12-11 04:18:13
问题 I am making a program for somebody, so they can exercise their eyes, and I am using the turtle, so it will move randomly. I want the turtle to bounce off the walls, so that it does not disappear off the sides, never to be seen again! I have looked at: TurtleGraphics Python: Bouncing turtle off the walls? and used some code from jnylen, so some credit goes to him! Anyway, here is my old, and terrible code (This is kept for reference): from random import * from turtle import * penup() # Get rid

Python Turtle Space Invaders bullets not hitting invaders

拥有回忆 提交于 2019-12-11 04:06:29
问题 I'm very new to turtle and python in general, so I apologize if my code seems messy. I'm currently coding a turtle version of space invaders and I can't figure out why my invaders aren't dying when they hit the turtles. The code seems to be the same as all the other space invader turtle programs I can find. Any help would be greatly appreciated. import turtle import random import math #### Player #### player1 = turtle.Turtle() player1.shape("arrow") player1.color("white") player1.speed(0)

Set no animation in Turtle - Python 3.4?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 03:43:27
问题 The code below creates a fractal tree. I want to draw it as quick as possible -- I don't want any animation to occur, otherwise it takes a long time to draw. In earlier versions of python, this is achieved with turtle.speed(0), as shown below. This doesn't work in python 3.4 import turtle import random red = 125 green = 70 blue = 38 pen = 10 def tree(branchLen, t, red, green, blue, pen): if branchLen > 3: pen = pen*0.8 t.pensize(pen) red = red - 15 green = green + 8 if branchLen > 5: angle =

Turtle.onkeypress not working (Python)

瘦欲@ 提交于 2019-12-11 02:58:43
问题 I'm very new to Python and have made a couple small games during a Python Learning course but never at home. So recently I began making a game, but after just 10 minutes I stumbled upon a problem: Nothing happened when I pressed "W" although I had writen onkeypress in the code. See for your self: (It's designed for full screen) import turtle s = turtle.Screen() g = turtle.Turtle() t = turtle.Turtle() #Ground t.speed(0) t.up() t.goto(-1000,-200) t.down() t.goto(1000,-200) #Player g.speed(0)

textinput() equivalent in python 2.x

↘锁芯ラ 提交于 2019-12-11 01:34:17
问题 I need to accept info from the user in python's turtle. however the turtle.textinput function only works in versions 3.x and upwards is there an alternative I can use in version 2.X ? 回答1: This is what textinput actually does: import tkSimpleDialog tkSimpleDialog.askstring('title', 'prompt') It requires you to have a turtle screen open, of course. 来源: https://stackoverflow.com/questions/20105816/textinput-equivalent-in-python-2-x

Ask user what shape to draw and how many in Python turtle

梦想的初衷 提交于 2019-12-11 00:14:54
问题 I am trying to make a program that asks the user to draw a shape and how many of that shape to draw in Python turtle. I dont know how to make the dialogue box so the user can say how many to add and make it run correctly. Any help will be awesome! Here is my code so far: import turtle steps = {"triangle": 3, "square": 4, "pentagon": 5, "hexagon": 6, "octagon": 7} #this is the dialogue box for what shape to draw and moving it over a bit so the #next shape can be seen def onkey_shape(): shape =

Get tkinter.tclerror when closing python turtle before it finished it's draw

*爱你&永不变心* 提交于 2019-12-10 23:32:16
问题 I have a python script that draws a koch snowflake. Everything works fine, except if I close the tutle graphics window before the drawing finished I get a long error with this as a final line: tkinter.tclerror: invalid command name ".38006576". I think it's like in java.swing: exit_on_close. Which is not the default. However I haven't found something like this for python turtle. Any suggestions how to avoid this? import turtle import sys import easygui as eg def isNum(s): try: int(s) return