FAQ Database Discussion Community


Python -Switch state of turtle pen using single keypress

python,tkinter,turtle-graphics
While writing a simple drawing program, I ran into a problem; I want to use the space key to switch the state of the pen from up to down and vice versa. Of course this could be achieved with an if event.char == "a key:" pen.penup() elif event.char == "another...

Ros Navigation Stack - Issue with zero and negative goal values

zero,turtle-graphics,ros,goal
I’m following the example of http://wiki.ros.org/navigation/Tutorials/SendingSimpleGoals with navigation stack. If I set the goal position with positive values the turtle moves as expected, but If it’s set to zero or negative values the turtle rotates in the same place, and It returns the message: “[ERROR] [1433622909.572352221]: Aborting because a valid...

How can I fill each petal separately using begin_fill()?

python,python-2.7,turtle-graphics
I have the following code that generates a petal pattern for a flower I'm trying to build. However, the problem is the fill part. What should happen is each petal to be filled individually: Instead, what happens is this: import turtle import math wn = turtle.Screen() wn.bgcolor("white") def draw_leaf(turtle, side,...

Attribute Error: 'list' object has no attribute 'split'

python,list,split,turtle-graphics
I am trying read a file and split a cell in each line by a comma and then display only the first and the second cells which contain information regarding the latitude and the longitude. This is the file: time,latitude,longitude,type2015-03-20T10:20:35.890Z,38.8221664,-122.7649994,earthquake2015-03-20T10:18:13.070Z,33.2073333,-116.6891667,earthquake2015-03-20T10:15:09.000Z,62.242,-150.8769,earthquake My program: def getQuakeData(): filename = input("Please enter the quake...

mainloop function from turtle class is not working, Python

python,turtle-graphics
This is my code : import turtle wn = turtle.Screen() alex = turtle.Turtle() alex.forward(50) alex.left(90) alex.forward(30) wn.mainloop() And my error is: "_Screen object has no attribute mainloop" I tried to do just "mainloop" but then I got NameError while doing alex.mainloop gave same error i.e. turtle object has no attribute...

Little assistance with my tic-tac-toe program

python,if-statement,while-loop,turtle-graphics
I need some help with my tic-tac-toe game that I created in Python 3. Have a look at my fun program and try it out. After that, please help me creating a while statement in my program. That is while the user choice of square if filled, you should continue...

Drawing shapes in python (turtle)

python,turtle-graphics
I am trying to draw a rectangle a rectangle using this function: drawRectangle(myTurtle, x, y, height, width, lineColor, fillColor) where the left-top corner coordinate is (x,y) code i have so far: def drawSquare(myTurtle,sideLength): for i in range(4): myTurtle.forward(sideLength) myTurtle.right(90) def drawRectangle(): import turtle t= turtle.Turtle() t.color('blue') t.fillcolor('yellow') t.begin_fill() drawRectangle(myTurtle, x,...

Drawing a indian flag chakra in python turtlee

python,turtle-graphics
I am drawing the Indian flag using turtle and python. I have got the rectangles and colours down so far, but am struggling to make the chakra in the middle. It has 24 spokes, and is surrounded by a closed circle. Any tips on how to accomplish this? This is...

How can I get my right mouse button to do things in a turtle application?

python,turtle-graphics
I'm trying to get my right mouse button to do something (skip the turtle to a new location without drawing a line, in this particular case) in Python. I'm in Lambert's Python Programming for Teens, which I love because the code all works. Except now, on page 130, we have...

How can i add an image (Python)

python,image,python-2.7,turtle-graphics
How can I add image to my Turtle Screen using turtle graphics? whenever I use functions like addshape i keep getting errors. does turtle graphics got an other way loading/importing images? for example: import turtle screen = turtle.Screen() image = r"C:\Users\--myName--\Desktop\Python\FinalPrj\rocketship.png" screen.addshape(image) turtle.shape(image) Thanks In Advance. i have been looking...

How to control the positioning of a turtle on a patch?

netlogo,turtle-graphics
In order for two way traffic to flow along a road that is the thickness of a single patch it is necessary for the position of each turtle to be to either the left or the right of the patch on which they are travelling. How can I control where...

What is the difference between `import turtle` and `from turtle import *`? [duplicate]

python,turtle-graphics
This question already has an answer here: What is the difference between import modx and from modx import *? 3 answers In Python, is it a good practice to import all attributes with a wildcard? 5 answers Besides the syntactic differences, I do not understand what the difference between...

Can I iterate over turtles / classes?

python,turtle-graphics
I have four turtles I want to be all at the same y pos and pass in an x pos to have them in a line along the bottom of the screen. I was wondering if this is possible with a for loop? code: from turtle import * canvas =...

Drawing random circles within a Python turtle circle

python,random,turtle-graphics
I'm trying to randomly place a number of small circles within a larger circle using turtle. The size of the larger circle depends on whether "small", "medium" or "large" are called, and I need the small circles to stay within the bounds of the radius of each circle. def drawCircle(myTurtle,...

Fixing function after debugging

python,python-3.x,turtle-graphics
I am trying to debug and fix this function where it is suppose to draw capital "i" when the depth is 2. I think I found the problem using pdb.set_trace() but not too sure how to fix it overall. This function results in half of capital "i". And in anyway...

why won't my circle loop work in python

python,loops,drawing,turtle-graphics
import turtle import time import random n = int(input("how many circles do you want? ")) radius = int(input("Radius?")) turtle.forward(radius) turtle.left(90) for circle in range(num, 0, -1):90 (num..1) turtle.begin_fill() turtle.color(random.random(),random.random(), random.random()) turtle.circle(radius * circle / num) turtle.end_fill() turtle.left(90) turtle.forward(radius / num) turtle.right(90) ...

AttributeError: '_Screen' object has no attribute 'mainloop'

python,python-2.7,graphics,turtle-graphics
I'm designing a simple Python program that uses the Turtle graphics module to draw lines on the screen with the arrow keys. import turtle turtle.setup(400,500) # Determine the window size wn = turtle.Screen() # Get a reference to the window wn.title("Handling keypresses!") # Change the window title wn.bgcolor("lightgreen") # Set...

turtle.xcor()/.ycor() if-statement comparison doesn't return true when it should

python,turtle-graphics
I'm trying to do a comparison of the turtles position with the bounds of my box to make sure it's in bounds. First I put the turtle at (0,0) and set playing to True with t.goto(0,0) playing = True Then I start the while loop (everything beyond here is in...

Recurions: simple spiral with python turtle

python,recursion,turtle-graphics
I'm trying to recreate a function spiral() using recursion that takes the parameters initLen (pixel length of first side), N (angle connecting segments), and mult (a float amount indicating how much bigger/smaller each segment should be after each turn - ex: mult = 0.5 means each segment would be half...

Python Turtle - Error with turtle.begin_fill() and turtle.end_Fill()

python,colors,turtle-graphics
I'm in a high school computer science class and I can't seem to find the correct placement/usage for turtle.begin_fill() and turtle.end_fill() to color in the shape I'm drawing. I've tried moving those two around and I keep getting this error: TypeError: begin_fill() takes 1 positional argument but 2 were given...

How do I modify the settings of the coordinates of the canvas using “Turtle” in Python 2.7.9?

python,math,canvas,turtle-graphics,sine
I would like my turtle to draw a sine curve in the range of y=(-1, 1). It works properly, but the size of the drawing is very tiny. If I multiply y by 50, it looks pretty good, but my task is to represent y=(-1, 1), so multiplying the y...

How to fill with multiple color in Python using turtle module?

python,turtle-graphics
I am pretty new in Python, now trying to have fun with it before going into serious stuffs. I am trying to draw a simple one wheel cart type something, where body and cart will have different colors. i am trying this code: import turtle truck = turtle.Turtle() truck.color("blue", "green")...