MyreMylar / pygame_gui_examples

Some examples of how to use pygame_gui
137 stars 42 forks source link

color of button #7

Open plotti opened 3 years ago

plotti commented 3 years ago

i simply want to change the color of some buttons why leaving others the same. i know i can theme all in the json file, but what about individual ones?

MyreMylar commented 3 years ago

You can also theme an individual button if you give it a unique object ID, or a class of buttons with a class ID. See the docs here:

https://pygame-gui.readthedocs.io/en/latest/theme_guide.html

And the ObjectID class here:

https://github.com/MyreMylar/pygame_gui/blob/0cbf7056518377b455d51a8d20167f4029756ad9/pygame_gui/core/ui_element.py#L19

Which you can pass into a button something like this:

https://github.com/MyreMylar/pygame_gui/blob/0cbf7056518377b455d51a8d20167f4029756ad9/pygame_gui/elements/ui_drop_down_menu.py#L116-L125

By convention, object ID strings begin with a # and class ID strings begin with a @ symbol.

These class and object IDs can be used in theme file blocks just like the element IDs and the precedence order goes object ID-> class ID-> element ID. So the theming parameters in any object ID block for an element will be used if they exist, if there are none it will look for any class ID parameters, and then for any element ID parameters - before finally using defaults if none of the other classes are found.