Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Turtle pen colour

When I call t.pencolor('83, 58, 27') (turtle is imported as t) I get the TurtleGraphicsError: bad color string: 83, 58, 27 even though I have (I think) changed my colour mode.

t.colormode(255)    
t.pencolor('83, 58, 27')

I run python 2.7 on OS 10.9

like image 965
Brennan Wilkes Avatar asked Mar 21 '23 11:03

Brennan Wilkes


1 Answers

You are passing in a string with three colors, where you need to pass the three colors as three separate integer arguments, like this:

t.pencolor(83, 58, 27)

There are multiple ways to use pencolor, from the documentation:

Four input formats are allowed:

pencolor() Return the current pencolor as color specification string or as a tuple (see example). May be used as input to another color/pencolor/fillcolor call.

pencolor(colorstring) Set pencolor to colorstring, which is a Tk color specification string, such as "red", "yellow", or "#33cc8c".

pencolor((r, g, b)) Set pencolor to the RGB color represented by the tuple of r, g, and b. Each of r, g, and b must be in the range 0..colormode, where colormode is either 1.0 or 255 (see colormode()).

pencolor(r, g, b) Set pencolor to the RGB color represented by r, g, and b. Each of r, g, and b must be in the range 0..colormode.

So you can also send in a tuple of your colors, but again they need to be integers not strings:

t.pencolor((83, 58, 27))
like image 108
Burhan Khalid Avatar answered Apr 01 '23 00:04

Burhan Khalid