turtle-graphics

How to keep run a game in window while we are inputting in terminal python [duplicate]

可紊 提交于 2021-02-05 06:44:45
问题 This question already has answers here : Is there a way that while running pygame, I can also run the console too? (2 answers) Closed last year . I am new to python programming i was writing a code of snake game in which snake moves randomly on x axis. And user have to put input in terminal for the location of food and poison on x axis. And snake must be inside the food and poison. "The main thing i want to that is while the user input any location of food and Poison the snake must move whole

Error when opening different windows in turtle using tkinter

帅比萌擦擦* 提交于 2021-01-29 15:17:40
问题 I have a problem using turtle with tkinter in Python 3.8. Still new to programming so thanks in advance! I have a tkinter window where you can chose to play either level one or two, every time you start the program either level will work but once you have finished the level and try another level, including the same level I get an error. error message: "Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\Kev\AppData\Local\Programs\Python\Python38\lib\tkinter\__init_

Get coordinates of “treasure” (turtles) in Maze Game that uses Python tkinter and turtle

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-29 14:50:44
问题 I am using Python 3 to make a maze using tkinter and turtle graphics. Most of the code works, except I cannot figure out how to "destroy" the "gold" in the game. Specifically, calling player.collision() , it says Question object has no attribute xcor even though I got this from a tutorial about a turtle Python maze game. I figured it would work the same as it did in that context, but with tkinter, everything seems to change. The problem occurs under player.collision() and the while loop at

Python turtle set direction of a turtle to another turtle

限于喜欢 提交于 2021-01-29 13:40:25
问题 I am using python 3.6 and turtle module. I have two turtles in another coordinates. how do i set the angle of turtle_1 to the direction of turtle_2? 回答1: turtle_1.setheading(turtle_1.towards(turtle_2)) This is typically used if you want turtle_1 to chase turtle_2 . The argument to towards() is flexible. Besides another turtle, it can also be separate X and Y arguments, or a tuple coordinate pair. If you simply want turtle_1 to point in the same direction as turtle_2 : turtle_1.setheading

Python module turtle not importing correctly

六眼飞鱼酱① 提交于 2021-01-29 11:33:32
问题 This is my fist time using the turtle module in python but i can't seem to import it? Here's my code: import turtle turtle.shape("turtle") turtle.speed(1) turtle.forward(100) turtle.left(90) turtle.forward(100) turtle.left(90) turtle.forward(100) turtle.left(90) turtle.forward(100) turtle.left(90) turtle.exitonclick() I run this as $ python3 example.py And I get $ python3 example.py Traceback (most recent call last): File "example.py", line 1, in <module> from turtle import * File "/usr/lib

Set the maximum distance that a turtle can go

泄露秘密 提交于 2021-01-29 10:17:33
问题 I want to set a maximum distance that a turtle can travel. Using the code below, I want the first turtle who moves distance x forward to stop all the turtles: for i in range(130): alex.forward(randint(5,10)) tess.forward(randint(5,10)) tim.forward(randint(5,10)) duck.forward(randint(5,10)) dog.forward(randint(5,10)) 回答1: You need just a bit more infrastructure than you currently have. To make it easier we'll need to work with individual elements of a list of turtles instead of individual

Turtle in Tkinter creating multiple windows

倾然丶 夕夏残阳落幕 提交于 2021-01-29 09:05:19
问题 I am attempting to create a quick turtle display using Tkinter, but some odd things are happening. First two turtle windows are being created, (one blank, one with the turtles), secondly, any attempt of turning the tracer off is not working. This might be a simple fix but at the moment I cannot find it. Any help would be appreciated, Below is the code: import tkinter as tk import turtle window = tk.Tk() window.title('Top 10\'s') def loadingscreen(): canvas = tk.Canvas(master = window, width =

Using screen.onclick() in Turtle with a function that returns multiple values

筅森魡賤 提交于 2021-01-29 07:08:24
问题 I am trying to use the coordinates from a user's mouse click as the x and y for another function. When that second function runs, it returns two values (not x and y). But when I run the onclick method, I get "TypeError: cannot unpack non-iterable NoneType object" before I even click anything. def on_click(x, y): t = turtle.Turtle() screen = turtle.Screen() t.penup() t.goto(x, y) #do stuff part 1 #do stuff part 2 return value1, value2 def main(): t = turtle.Turtle() screen = turtle.Screen()

How can I make a turtle do something when it gets close to another turtle?

独自空忆成欢 提交于 2021-01-28 20:32:54
问题 Good afternoon, I am simulating a virus outbreak with the use of turtles. I have come up with the following code, my question will be after the code: import turtle import random import time def make_population(amount): """ Creates a list representing a population with a certain amount of people. """ population = [] for person in range(amount): population.append(turtle.Turtle()) for person in population: person.shape("circle") person.shapesize(0.2) return population def random_move(person): ""

Python Turtle.Terminator even after using exitonclick()

偶尔善良 提交于 2021-01-28 07:38:00
问题 I have tried to make functions for turtle to make it extremely easy to draw shapes and the code looks like this import turtle as t def square(): tw = t.Screen() for i in range(4): t.forward(100) t.right(90) tw.exitonclick() def triangle(): tw = t.Screen() for i in range(3): t.forward(100) t.right(120) tw.exitonclick() def star(): tw = t.Screen() for i in range(5): t.forward(150) t.right(144) tw.exitonclick() when i run this code in shell a problem is fonud... >>> square() >>> triangle()