turtle-graphics

Python Collision Detection with x and y coordinates for border

风流意气都作罢 提交于 2020-01-25 04:58:10
问题 Im working on a python turtle game where the turtle can move with commands but it has to be able to detect collision with rectangles and circles on the screen as well as the border. I have no idea how to do this can anyone help? 回答1: Collision is easy! Before the nitty gritty, you need to understand how to obtain the distance between two points. If you have not done this before it is just pythag! If you picture two points on a plane (red points on the picture), the shortest distance to travel

End Python turtle drawing so user goes back to main menu

巧了我就是萌 提交于 2020-01-17 08:37:50
问题 I'm making a code so that when a user clicks on the window, it will draw the shape based on their input of choice. I'm having trouble on where I should assign the window and turtle correctly and how to assign to a function a way to quit the window its currently on. Is there any way for me to end a mainloop() so that the user goes back to the main menu after clicking and making as many of their chosen shapes (given that each time they do choose an option, the window resets to a blank state)?

Python turtle get tkinter root

匆匆过客 提交于 2020-01-14 05:33:28
问题 Python turtle works with tkinter. How to get the root you know from tkinter? Like this: import tkinter root = tkinter.Tk() but for turtle. 回答1: The top-level widget is available through the winfo_toplevel method of the turtle canvas: import turtle canvas = turtle.getcanvas() root = canvas.winfo_toplevel() It is of a subtype of Tk : import tkinter assert type(root) is turtle._Root assert isinstance(root, tkinter.Tk) 回答2: turtle.getcanvas() returns the object you are (I am) looking for. 来源:

Making snake in Python, can't get bodies to follow head etc

拈花ヽ惹草 提交于 2020-01-06 06:07:33
问题 I wanted to make a snake game in turtle but I can't seem to get the tail segments to follow the leader. As if to say I can't get the first body part to follow the head, and then the second body part to follow the first body, etc. I tried using what maths I have but I can't seem to get it to calculate where the head just was or where the body in front of it just was. here is my code: #libraries import turtle import random import math #screen the_screen = turtle.Screen() the_screen.bgcolor(

How do you draw an ellipse/oval in turtle graphics (python)?

孤街醉人 提交于 2020-01-05 04:54:06
问题 How do you draw an ellipse/oval in turtle graphics (python)? I want to be able to draw an ellipse and part of an ellipse using the circle() function or similar. I can stamp one using #turtlesize(stretch_wid=None, stretch_len=10, outline=None). But I don't want it to be color filled. 回答1: You can use shapesize() function of turtle to make an ellipse. shape("circle") shapesize(5,4,1) fillcolor("white") 回答2: I made my own function for drawing ovals that I personally think is very useful: def

Integrate turtle module with tkinter canvas [closed]

北城余情 提交于 2020-01-04 13:21:19
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . I am trying to integrate the Turtle module into an interface I have created with TKInter, currently I have a canvas where I would like for the turtle to draw to (see example 1). However I am lost in how to get the draw to it. 回答1: import turtle import tkinter as tk def forward(): t.forward(100) def back(): t

How do I run two turtles in python simultaneously?

不羁的心 提交于 2020-01-04 11:43:08
问题 I'm trying to make two turtles move together instead of one moving subsequently after the other. For example: a = turtle.Turtle() b = turtle.Turtle() a.forward(100) b.forward(100) But this only makes them move one after the other. Is there a way to make them move together simultaneously? 回答1: Is there a way to make them move together simultaneously? The best we can hope to do is make them appear to move simultaneously. Below are three increasingly complex approaches to this problem. But first

How do I run two turtles in python simultaneously?

我与影子孤独终老i 提交于 2020-01-04 11:42:11
问题 I'm trying to make two turtles move together instead of one moving subsequently after the other. For example: a = turtle.Turtle() b = turtle.Turtle() a.forward(100) b.forward(100) But this only makes them move one after the other. Is there a way to make them move together simultaneously? 回答1: Is there a way to make them move together simultaneously? The best we can hope to do is make them appear to move simultaneously. Below are three increasingly complex approaches to this problem. But first

Start and stop Python turtle with space bar

假如想象 提交于 2020-01-04 09:36:07
问题 I am trying to code a program that starts and stops a turtle by pressing the space bar. I got the code to start the turtle moving but it doesn't stop it when I press it again. It seems to just increase the speed. Here are my coding requirements and the code I typed up. Create a turtle program with three functions to control the turtle. Create a function called turnLeft that turns the turtle 90 degrees left when the right arrow is pressed on the keyboard. Create a function called turnRight

how to rotate text in python's turtle graphics

青春壹個敷衍的年華 提交于 2020-01-03 18:55:26
问题 I want to make diagrams with python's turtle (teaching purposes). The label "values" for the y-axis should be rotated. Python's turtle has a method to write a string at current position: from turtle import * left(90) # does not help write("values", font=('Arial', 12, 'normal')) hideturtle() mainloop() "values" is still horizontal. How can I rotate text with python's turtle? 回答1: It's not possible to write rotated text with turtle. See http://www.gossamer-threads.com/lists/python/bugs/879806: