Questions tagged [python-turtle]

The python turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways.

507 questions
6
votes
4 answers

How to prevent turtle from moving in opposite direction

Code: import turtle import random import time s = turtle.getscreen() turtle.screensize(canvwidth=400, canvheight=400) t = turtle.Turtle() t.pensize(0) t.shape('square') t.color("black") t.speed(0) t.penup() def moveu(num): t.setheading(num) …
red_panda
  • 335
  • 15
5
votes
2 answers

Python - Turtle recreating image too slow

I got curious and wondered if I could have the pyautogui module detect the color from every few pixels from an image and have turtle recreate them in it's canvas using small circles. I ended up finding a way to make it work, and I liked how the…
4
votes
1 answer

How do I add an image to the turtle screen without getting an error?

I have seen other people ask this question and I have looked it up. However, I still get the same error. Error: 'str' object has no attribute '_type'. Here is my code: from turtle import * setup(600,600) Screen() sc = Screen() alien =…
Matt
  • 124
  • 10
4
votes
2 answers

Python Turtle - Turtle Location

I want to make the turtle goto the floor if it is above a set of coordinates: something like this: floor = -323 if turtle above floor: turtle.goto(floor) But I don't know how the 'if' statement would work, as you can't simply put 'if turtle…
A Display Name
  • 327
  • 8
  • 18
4
votes
2 answers

Change appearance of turtle

I am programming in python 3.2.2 turtle. I am able to make the turtle follow my cursor when I clack but now I have trouble changing the appearance of the turtle. In my code you will see a tank, and I want the image of the tank to be my turtle. Here…
bertrand
  • 111
  • 2
  • 10
3
votes
3 answers

Turtle Maze in python. I do not know how to avoid the turtle passing walls and cheat

i am a complete beginner to coding and at school we started learning python. My little cousin discovered that, and asked me to make a game... since i am not an expert i decided to do a simple game, a maze. I coded some functions to generate the maze…
3
votes
1 answer

How to get multiple keybindings to work simultaniously in turtle graphics?

I am making a game in python called pong. Can I get 2 different turtles in turtle graphics to respond simultaneously to keybindings? Here is the code: import turtle class paddle(turtle.Turtle): def __init__(self, x_cord, keybindings): …
3
votes
2 answers

Python Turtle transparent fill?

I'm trying to recreate this picture using the Turtle library: but I'm struggling when trying to make the inner circles 'transparent'. I searched the documentation but found no way to change the opacity of the circle's fill color. What I tried…
Yarin B
  • 33
  • 3
3
votes
1 answer

How to make turtle draw quicker?

My code: import turtle screen = turtle.Screen() bob = turtle.Turtle() screen.bgcolor("black") bob.speed(0) def crazy(): for i in range(360): for colors in ['red', 'yellow', 'green', 'purple', 'orange', 'blue']: …
3
votes
2 answers

The rule of thumb as to when we should use a global variable in a function

When I code games with functions, I often get confused as to which variable to global. I've heard that globalizing variables isn't a very practice, so I try to minimize the amount by not globalizing any, and only globalize the ones that the error…
Ann Zen
  • 17,892
  • 6
  • 20
  • 39
3
votes
1 answer

screensize of turtle in python

I am trying to work with the screen in turtle and am confused about the dimensions of the screen. So in this example: import turtle screen = turtle.Screen() print(screen.screensize()) turtle.done() Python prints the dimension of the turtle…
3
votes
1 answer

Is there a way to change the location of a text box in turtle? It always shows up in the top left for me, but I want it in the bottom center

import turtle screen = turtle.Screen() global answer answer = screen.textinput("Welcome to the game", "What's your name?") Here is a screenshot of what comes up. I can't seem to find anything describing a way to edit the box at all. I'm also…
3
votes
1 answer

How do I hide something a turtle drew previously?

I used turtle.write to write something on the screen. How do I hide it completely. Not the turtle icon thing, but what's written.
penny12
  • 57
  • 4
3
votes
1 answer

Can you get user input with turtle.write?

I want to ask the user a question using turtle.write and get input. Is that possible?
penny12
  • 57
  • 4
3
votes
2 answers

Don't understand this AttributeError: module 'turtle' has no attribute 'Turtle'

#archimedes spiral by rays import math import turtle def spiral(t, a, b): diff=5 number=500 for i in range(number): t.penup() t.fd(a+b*i*diff*math.pi/180) t.pendown() t.lt(90) t.fd(10) …
Manish Kumar
  • 85
  • 1
  • 1
  • 8
1
2 3
33 34