![]() |
VOOZH | about |
In this article, we will learn How we can create buttons in Arcade using python.
In Arcade we can easily add buttons to our game.
For this, we will use some functions:
Syntax: arcade.gui.UIManager(window, auto_enable)
Parameters:
- window : Our game window
- auto_enable : Accepts a boolean value
Syntax: arcade.gui.UIBoxLayout(x, y, vertical, align, children, size)
Parameters:
- x : x coordinate of bottom left
- y : x coordinate of bottom left
- vertical : Layout children vertical (True) or horizontal (False)
- align : Align children in orthogonal direction (x: left, center, right / y: top, center, bottom)
- children : Initial children, more can be added
- size : A hint for UILayout, if this UIWidget would like to grow
Syntax: arcade.gui.UIFlatButton( x, y, width, height, text, style)
Parameters:
- x : x-coordinate of widget.
- y : y-coordinate of widget.
- width : width of widget. Defaults to texture width if not specified.
- height : height of widget. Defaults to texture height if not specified.
- text : text to add to the button.
- style : Used to style the button
Now to create our button we are going to create a class named MainClass and inside this class, we are going to initialize one variable for the UIManager. After that, we will create our button using the UIFlatButton() then we will add this button in our UIManager. Then we will create an on_draw() function to draw our button.
Below is the implementation:
Output:
👁 ImageNow we are going to create an on_buttonclick() function which will be called every time the user presses the button.