turtle-graphics

Python Turtle Graphics Keyboard Commands

ぐ巨炮叔叔 提交于 2021-02-18 08:37:40
问题 Anybody have any insight into controlling turtle graphics in python 2.7 with keyboard commands? I have done extensive research on this website and others and feel like I am doing the right thing but it just doesn't want to work for me. Below is what I have so far, can anyone tell me where I am going wrong???? from turtle import * turtle.setup(500, 500) wn = turtle.Screen() wn.title("Turtle Keys") move = turtle.Turtle() showturtle() def k1(): move.forward(45) def k2(): move.left(45) def k3():

Close turtle window by X button(close)

对着背影说爱祢 提交于 2021-02-17 05:18:29
问题 I'm coding Python and I'm learning Turtle. When I close turtle window by X button I'm getting an error. What can I do? 回答1: Use a try - except block in each iteration of your while loop to detect when the user clicks the X button. When the click is detected, use break to break out of the loop. From: import turtle while True: # Your game loop code turtle.update() to import turtle while True: try: # Your game loop code turtle.update() except turtle.Terminator: break 回答2: Usually, errors

How to implement a drag feature (or zoom) in a python window application?

拥有回忆 提交于 2021-02-10 20:47:52
问题 I'm doing some simple fractal drawings using turtle graphics in python and have encountered the situation where the turtle draws beyond the application frame. I want to be able to drag the view within the window so that I can center it over a different section of the fractal I am drawing or alternatively, Zoom in or out in order to manipulate the view. Does Python have a module for this? I am relatively new to python as I primarily program with Java and can think of many ways to do with Java

Python Turtle `While True` in Event Driven Environment

送分小仙女□ 提交于 2021-02-10 20:47:51
问题 I have read in several posts here on Stack Overflow that "An event-driven environment like turtle should never have while True: as it potentially blocks out events (e.g. keyboard)." Here is a Python Turtle program that seems to work fine, but which uses the while True: construct. Could someone please explain why this approach is wrong, what problems is creates and what the correct way is to achieve the same result? import turtle import time def move_snake(): """ This function updates the

Python Turtle `While True` in Event Driven Environment

空扰寡人 提交于 2021-02-10 20:44:31
问题 I have read in several posts here on Stack Overflow that "An event-driven environment like turtle should never have while True: as it potentially blocks out events (e.g. keyboard)." Here is a Python Turtle program that seems to work fine, but which uses the while True: construct. Could someone please explain why this approach is wrong, what problems is creates and what the correct way is to achieve the same result? import turtle import time def move_snake(): """ This function updates the

How to center text using “turtle” module in Python

寵の児 提交于 2021-02-10 14:39:58
问题 How can I draw "turtle" text starting from the center of a window? I know how to create "turtle" text, but I don't know how to center the text so it appears from the center of a window. turtle.write("I AM HERE", font=("Arial", 50, "bold")) Thanks for your help, Howard 回答1: To center text on a point (e.g. the origin at [0, 0]), in the X dimension, you can use the align=center keyword argument to turtle.write() . To get alignment in the Y dimension, you need to adjust slightly for the font size

Turtle tracer arguments example trouble

人走茶凉 提交于 2021-02-10 14:26:59
问题 What is the exact usage of Turtle.tracer? In python docs it is written Turn turtle animation on/off and set delay for update drawings. I use it for disabling animation but the arguments are not clear for example in this code if I use turtle.trace turtle doesn't draw rest of table how to set correct arguments. import turtle turtle.width(5) yd=xd=-64 turtle.tracer(8,25)#This is the problem for i in range(2): turtle.up() turtle.goto(-197.5,yd) turtle.down() turtle.seth(0) turtle.fd(394) yd+=128

Turtle tracer arguments example trouble

拟墨画扇 提交于 2021-02-10 14:25:44
问题 What is the exact usage of Turtle.tracer? In python docs it is written Turn turtle animation on/off and set delay for update drawings. I use it for disabling animation but the arguments are not clear for example in this code if I use turtle.trace turtle doesn't draw rest of table how to set correct arguments. import turtle turtle.width(5) yd=xd=-64 turtle.tracer(8,25)#This is the problem for i in range(2): turtle.up() turtle.goto(-197.5,yd) turtle.down() turtle.seth(0) turtle.fd(394) yd+=128

How to fix inconsistent frame rate (speed) in python turtle

梦想的初衷 提交于 2021-02-10 13:25:13
问题 I a made pong game by following this tutorial https://youtu.be/C6jJg9Zan7w The problem I'm having is that speed of the ball (turtle object) is not the same on different computers. For example, on the tutorial instructor's computer the value of ball.dx ball.dy is 2 and the ball speed is normal but on my computer is really fast so I had to set it to 0.1. I think this problem is because different computers can put out more or less frame. I know there is a method in popular game engines (like

How to fix inconsistent frame rate (speed) in python turtle

跟風遠走 提交于 2021-02-10 13:25:06
问题 I a made pong game by following this tutorial https://youtu.be/C6jJg9Zan7w The problem I'm having is that speed of the ball (turtle object) is not the same on different computers. For example, on the tutorial instructor's computer the value of ball.dx ball.dy is 2 and the ball speed is normal but on my computer is really fast so I had to set it to 0.1. I think this problem is because different computers can put out more or less frame. I know there is a method in popular game engines (like