How to use hexadecimal values in python instead of RGB value. Python 2.7

Viewed 17162

I don't like RGB, I use HEX instead. I'm new to Python and this is how my code is looking like; How do I use HEX. I'm sorry for english I'm not from USA.

import pygame

black = (0,0,0)
white = (255,255,255)
blue = ("#7ec0ee")

pygame.init()

size = 1024,768
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Code for Stack")

done = False
clock = pygame.time.Clock()

while not done:
    for event in pygame.event.get():
      if event.type == pygame.QUIT:
        done = True

      screen.fill(blue)

      pygame.display.flip()
      clock.tick(60)

pygame.quit()
1 Answers

pygame.Color supports hex arguments. So you can do this:

blue = pygame.Color("#7ec0ee")
screen.fill(blue)

This automatically converts your color to RGBA values. So if you went to print the color, you would see:

(126, 192, 238, 255)
Related