When you call stddraw.setPenColor
you can use the stddraw
colours like stddraw.BLACK
, stddraw.RED
, stddraw.GREEN
, stddraw.BOOK_BLUE
, and so on. But these colors may not fit your application or you may want to create something that stands out, a UI marvel!
Using Custom Colours
Using custom colours is pretty straightforward. Simply start by importing the Color
class:
from color import Color

And then create Color
objects:
MY_BLACK_COLOR = Color(0, 0, 0)
MY_WHITE_COLOR = Color(255, 255, 255)

Color
uses the RGB system to generate colours based on the units of Red, Green and Black. The units have a minimum value of 0 and a maximum value of 255. Colours are always written with the Red value first, the Green value second, and the Blue value third. Memorise "RGB" and you will remember the ordering.
Where can I get the RGB values?
Let’s say you wanted this orange:
You can use Google’s Color Picker to get the RGB values of the desired colour:
Then you copy the RGB values:
And paste the RGB values to create your Color
object:
HACKER_BYTES_ORANGE = Color(217, 121, 58)
def draw_gui():
...
# you can use your color at anytime
stddraw.setPenColor(HACKER_BYTES_ORANGE)
stddraw.filledRectangle(x, y, rect_w, rect_h)
...

Pro tip
It’s never a good idea to think of colours for a Graphical User Interface in isolation, that’s how you end up with a combination of clashing colours. It’s better to think about all the colours you would like to use on your User Interface in one go so that you ensure they go together. To develop a Color Scheme for your Graphical User Interface you can use coolors:
You can randomise the colours by pressing the spacebar key and locking in colours as you find colours you like. You can even hit the +
between colours to add colours or shift around colours to see which ones clash or match.