Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using color in python
#12
Is this what you are talking about.
import pygame

class PygameColors:
    def __init__(self):
        self.__dict__.update(pygame.color.THECOLORS)

    def __getitem__(self, key):
        return self.__dict__[key]

    def add(self, name, r, g, b, a=255):
        if name not in vars(self).keys():
            setattr(self, name, pygame.Color(r, g, b, a))
        else:
            print("Color already exists:", name)

color = PygameColors()

print("white:", color["white"], color.white, pygame.Color("white"))
99 percent of computer problems exists between chair and keyboard.
Reply


Messages In This Thread
Using color in python - by Help_me_Please - Sep-14-2019, 03:39 PM
RE: Using color in python - by ndc85430 - Sep-14-2019, 03:45 PM
RE: Using color in python - by Help_me_Please - Sep-14-2019, 03:47 PM
RE: Using color in python - by ndc85430 - Sep-14-2019, 03:50 PM
RE: Using color in python - by Help_me_Please - Sep-14-2019, 04:13 PM
RE: Using color in python - by ndc85430 - Sep-14-2019, 04:16 PM
RE: Using color in python - by SheeppOSU - Sep-14-2019, 07:59 PM
RE: Using color in python - by Windspar - Sep-15-2019, 11:21 AM
RE: Using color in python - by Piethon - Sep-22-2019, 10:56 AM
RE: Using color in python - by Windspar - Sep-22-2019, 10:54 PM
RE: Using color in python - by adt - Sep-23-2019, 04:06 PM
RE: Using color in python - by Windspar - Sep-23-2019, 10:27 PM
RE: Using color in python - by adt - Sep-24-2019, 05:19 AM
RE: Using color in python - by SheeppOSU - Sep-28-2019, 04:09 PM
RE: Using color in python - by adt - Sep-29-2019, 04:13 AM
RE: Using color in python - by Windspar - Sep-30-2019, 10:39 AM
RE: Using color in python - by adt - Sep-30-2019, 02:58 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020