GUI Custom Style

GUI Custom Style
gui_custom_style.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
This example shows how to programmatically change the GUI style.

You can run this example with:
python -m arcade.examples.gui_custom_style

This can also be done with a yaml file.
See:
https://github.com/pvcraven/arcade/blob/development/arcade/resources/style/default.yml
and the UIStyle.from_file() command.
"""
import arcade

import arcade.gui
from arcade.gui import UIFlatButton, UIGhostFlatButton, UIManager
from arcade.gui.ui_style import UIStyle

class MyView(arcade.View):

    """ Main program view """
    def __init__(self):
        """ Set up this view """
        super().__init__()

        self.ui_manager = UIManager()

    def setup(self):
        """ Setup the view """
        self.ui_manager.purge_ui_elements()
        flat = UIFlatButton('Hello world', center_x=200, center_y=self.window.height // 2, width=200, height=40)
        flat.set_style_attrs(
            font_color=arcade.color.WHITE,
            font_color_hover=arcade.color.WHITE,
            font_color_press=arcade.color.WHITE,
            bg_color=(51, 139, 57),
            bg_color_hover=(51, 139, 57),
            bg_color_press=(28, 71, 32),
            border_color=(51, 139, 57),
            border_color_hover=arcade.color.WHITE,
            border_color_press=arcade.color.WHITE
        )
        self.ui_manager.add_ui_element(flat)

        # creates a new class, which will match the id
        UIStyle.default_style().set_class_attrs(
            'right_button',
            font_color=arcade.color.WHITE,
            font_color_hover=arcade.color.WHITE,
            font_color_press=arcade.color.WHITE,
            bg_color=(135, 21, 25),
            bg_color_hover=(135, 21, 25),
            bg_color_press=(122, 21, 24),
            border_color=(135, 21, 25),
            border_color_hover=arcade.color.WHITE,
            border_color_press=arcade.color.WHITE
        )
        self.ui_manager.add_ui_element(UIGhostFlatButton(
            'Hello world',
            center_x=600,
            center_y=self.window.height // 2,
            width=200,
            height=40,
            id='right_button'
        ))

    def on_draw(self):
        """ Draw this view """
        arcade.start_render()
        arcade.set_background_color(arcade.color.BLACK)

    def on_show_view(self):
        """ Show this view """
        self.setup()


if __name__ == '__main__':
    window = arcade.Window(title='ARCADE_GUI')
    window.show_view(MyView())
    arcade.run()