Flat Text Button Styled#

gui_flat_button_styled.py#
 1"""
 2Example code showing how to style UIFlatButtons.
 3
 4If Python and Arcade are installed, this example can be run from the command line with:
 5python -m arcade.examples.gui_flat_button_styled
 6"""
 7import arcade
 8import arcade.gui
 9import arcade.gui.widgets.buttons
10import arcade.gui.widgets.layout
11from arcade.gui import UIFlatButton
12
13
14class MyWindow(arcade.Window):
15    def __init__(self):
16        super().__init__(800, 600, "UIFlatButton Example", resizable=True)
17
18        # --- Required for all code that uses UI element,
19        # a UIManager to handle the UI.
20        self.manager = arcade.gui.UIManager()
21        self.manager.enable()
22
23        # Set background color
24        arcade.set_background_color(arcade.color.DARK_BLUE_GRAY)
25
26        # Render button
27        red_style = {
28            "normal": UIFlatButton.UIStyle(
29                font_size=12,
30                font_name=("calibri", "arial"),
31                font_color=arcade.color.WHITE,
32                bg=arcade.color.RED,
33                border=None,
34                border_width=0,
35            ),
36            "hover": UIFlatButton.UIStyle(
37                font_size=12,
38                font_name=("calibri", "arial"),
39                font_color=arcade.color.WHITE,
40                bg=arcade.color.REDWOOD,
41                border=arcade.color.RED,
42                border_width=2,
43            ),
44            "press": UIFlatButton.UIStyle(
45                font_size=12,
46                font_name=("calibri", "arial"),
47                font_color=arcade.color.WHITE,
48                bg=arcade.color.RED_BROWN,
49                border=arcade.color.REDWOOD,
50                border_width=2,
51            ),
52            "disabled": UIFlatButton.UIStyle(
53                font_size=12,
54                font_name=("calibri", "arial"),
55                font_color=arcade.color.WHITE,
56                bg=arcade.color.COOL_GREY,
57                border=arcade.color.ASH_GREY,
58                border_width=2,
59            )
60        }
61
62        # Create a vertical BoxGroup to align buttons
63        self.v_box = arcade.gui.widgets.layout.UIBoxLayout(space_between=20)
64
65        # Create the buttons
66        demo_button_1 = arcade.gui.widgets.buttons.UIFlatButton(
67            text="Demo 1", width=200, style=UIFlatButton.DEFAULT_STYLE
68        )
69        demo_button_2 = arcade.gui.widgets.buttons.UIFlatButton(
70            text="Demo 2", width=200, style=red_style
71        )
72
73        self.v_box.add(demo_button_1)
74        self.v_box.add(demo_button_2)
75
76        # Create a widget to hold the v_box widget, that will center the buttons
77        ui_anchor_layout = arcade.gui.widgets.layout.UIAnchorLayout()
78        ui_anchor_layout.add(child=self.v_box, anchor_x="center_x", anchor_y="center_y")
79
80        self.manager.add(ui_anchor_layout)
81
82    def on_draw(self):
83        self.clear()
84        self.manager.draw()
85
86
87window = MyWindow()
88arcade.run()