0

Hi, I am trying to write a snippet of code that checks if the user entered a valid color from an imported file called graphics.py.

# Get a valid color value from the user.
    color = raw_input("Enter a color: ")

graphics.py contains a huge list of built in color names such as:

DarkOrchid4
DarkRed
DarkSalmon
DarkSeaGreen
DarkSeaGreen

How do I have it so my code checks that the user entered something that is within that huge list of colors?

Thanks

4
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by woooee
0
theySaid = raw_input("Please enter a, b, or c: ")
if theySaid not in ["a", "b", "c"]:
    print "You didn't follow my instructions. Sad Panda..."
0

I am not sure which version of graphics.py you are using. The version I have (Version 4.0 08/2009) does not show any colors, it simply uses the color names supplied by Tkinter.

0

You draw an object like a circle and fill it with the color selected inside a try/except. It will fail if it is not a valid color. I think Tkinter uses an r,g,b tuple so your program should accept that as well as a name.

Edited by woooee: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.