Flat Text Button Styled#

gui_flat_button_styled.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
80
81
82
83
84
85
86
87
88
"""
Example code showing how to style UIFlatButtons.

If Python and Arcade are installed, this example can be run from the command line with:
python -m arcade.examples.gui_flat_button_styled
"""
import arcade
import arcade.gui
import arcade.gui.widgets.buttons
import arcade.gui.widgets.layout
from arcade.experimental.uistyle import UIFlatButtonStyle, UIFlatButtonStyle_default


class MyWindow(arcade.Window):
    def __init__(self):
        super().__init__(800, 600, "UIFlatButton Example", resizable=True)

        # --- Required for all code that uses UI element,
        # a UIManager to handle the UI.
        self.manager = arcade.gui.UIManager()
        self.manager.enable()

        # Set background color
        arcade.set_background_color(arcade.color.DARK_BLUE_GRAY)

        # Render button
        red_style = {
            "normal": UIFlatButtonStyle(
                font_size=12,
                font_name=("calibri", "arial"),
                font_color=arcade.color.WHITE,
                bg=arcade.color.RED,
                border=None,
                border_width=0,
            ),
            "hover": UIFlatButtonStyle(
                font_size=12,
                font_name=("calibri", "arial"),
                font_color=arcade.color.WHITE,
                bg=arcade.color.REDWOOD,
                border=arcade.color.RED,
                border_width=2,
            ),
            "press": UIFlatButtonStyle(
                font_size=12,
                font_name=("calibri", "arial"),
                font_color=arcade.color.WHITE,
                bg=arcade.color.RED_BROWN,
                border=arcade.color.REDWOOD,
                border_width=2,
            ),
            "disabled": UIFlatButtonStyle(
                font_size=12,
                font_name=("calibri", "arial"),
                font_color=arcade.color.WHITE,
                bg=arcade.color.COOL_GREY,
                border=arcade.color.ASH_GREY,
                border_width=2,
            )
        }

        # Create a vertical BoxGroup to align buttons
        self.v_box = arcade.gui.widgets.layout.UIBoxLayout(space_between=20)

        # Create the buttons
        demo_button_1 = arcade.gui.widgets.buttons.UIFlatButton(
            text="Demo 1", width=200, style=UIFlatButtonStyle_default
        )
        demo_button_2 = arcade.gui.widgets.buttons.UIFlatButton(
            text="Demo 2", width=200, style=red_style
        )

        self.v_box.add(demo_button_1)
        self.v_box.add(demo_button_2)

        # Create a widget to hold the v_box widget, that will center the buttons
        ui_anchor_layout = arcade.gui.widgets.layout.UIAnchorLayout()
        ui_anchor_layout.add(child=self.v_box, anchor_x="center_x", anchor_y="center_y")

        self.manager.add(ui_anchor_layout)

    def on_draw(self):
        self.clear()
        self.manager.draw()


window = MyWindow()
arcade.run()