0

I'm trying to make a code that check the turle's current color in python, something like this:

if turtle.color()=='gray':
    pass
else:
    color = input('type some color: ')
turtle.color(color)

But for some reason, it's not working...
Also, I tried to print it, that what I got:

print(turtle.color())
#output
('gray', 'gray')
martineau
  • 119,623
  • 25
  • 170
  • 301
plsHelpMe
  • 15
  • 6

2 Answers2

0

turtle.color() return color in format of how you provide color for setting color as shown in documentation. You need to add more condition in if for all formats of gray like HexCode of gray, array set as given in above your case.

 >>> turtle.color("red", "green")
 >>> turtle.color()
 ('red', 'green')
 >>> color("#285078", "#a0c8f0")
 >>> color()
 ((40.0, 80.0, 120.0), (160.0, 200.0, 240.0))

ref: turtle.color documentation.

martineau
  • 119,623
  • 25
  • 170
  • 301
Awais Latif
  • 101
  • 1
  • 7
0

Turtles have two colors, their outline color, which they draw with, known as the pen color and their body color, which they fill with, known as their fill color. There are separate methods for setting and retrieving pen and fill color, pencolor() and fillcolor(), one of which is likely what you want:

if turtle.pencolor() != 'gray':
    color = input("Type some color: ")
    turtle.pencolor(color)

Turtle's color() method is used to set both the pen and fill color, which is why it will accept and return two colors. (If given only one color, it will set both the pen and fill color to that same color.) It's a convenience function but generally not what you want when interrogating a turtle's color(s).

cdlane
  • 40,441
  • 5
  • 32
  • 81