0

I am trying to get the following ENUM to work, but it's not working. Any help is appreciated.

class Colour(Enum):
    WHITE = (255,255,255)
    BLACK = (0,0,0)
    RED = (215,45,45)
    BLUE = (45,87,214)
    YELLOW = (230,223,48)
    GREEN = (45,194,64)

Using it: Colour.BLACK

Error:

/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 "/Users/blooop/main.py"
Traceback (most recent call last):
  File "/Users/bloopppp/main.py", line 27, in <module>
    gameDisplay.fill(Colour.BLACK)
TypeError: invalid color argument

Process finished with exit code 1

I'm still learning Python, so all help is greatly appreciated!

Thank you!

4
Contributors
6
Replies
45
Views
2 Years
Discussion Span
Last Post by matrixdevuk
1

You need to use at least Python version 3.4 ...

''' enum_test101.py
module enum is new in Python34
see: http://legacy.python.org/dev/peps/pep-0435/
'''

from enum import Enum

class Colour(Enum):
    WHITE = (255,255,255)
    BLACK = (0,0,0)
    RED = (215,45,45)
    BLUE = (45,87,214)
    YELLOW = (230,223,48)
    GREEN = (45,194,64)

print(Colour.BLACK.value)  # (0, 0, 0)
1

I installed it via $ pip install enum34. It was backported.
The syntax is registering perfectly with PyCharm v3 (by JetBrains).
See the answer here.

Thanks for the quick response.

1

In ubuntu there is a package python-enum34 for this, together with 3 other enum packages for python.

0

According to your traceback you are using Python2.7

Why not use just constants:

WHITE = (255,255,255)
BLACK = (0,0,0)
RED = (215,45,45)
BLUE = (45,87,214)
YELLOW = (230,223,48)
GREEN = (45,194,64)

Edited by sneekula

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.