Hello this is My first post on stackoverflow, so I apologize in advance if my post is irrelant or problematic.
I am using the python libraries Arcade and Arcade.gui.
Currently I try to add GUI widgets in a Section instance (named popup in the code below). The button is visible but my problem is : it seems to be inactive. It doesn't react to hovering or click (images are in the same folder as source code)
Thanks for helping.
My minimal code :
import arcade
import arcade.gui
class Popup(arcade.Section):
def __init__(self, left: int, bottom: int, width: int, height: int, **kwargs):
super().__init__(left, bottom, width, height, **kwargs)
self.ui_manager = arcade.gui.UIManager()
self.ui_manager.enable()
box = arcade.gui.UIBoxLayout()
button = arcade.gui.UITextureButton(
x=0, y=0,
texture=arcade.load_texture('button.png'),
texture_hovered=arcade.load_texture('button_hovered.png'),
texture_pressed=arcade.load_texture('button_pressed.png'),
text='Click !'
)
box.add(button)
button.on_click = self.on_click_button
anchored_box = arcade.gui.UIAnchorWidget(anchor_x="center_x", anchor_y="center_y", child=box)
self.manager.add(anchored_box)
def on_click_button(self, event):
print('clicked')
def on_draw(self):
self.manager.draw()
class GameView(arcade.View):
def __init__(self):
super().__init__()
popup_width = 400
popup_height = 300
popup_left = self.window.width // 2 - popup_width // 2
popup_bottom = self.window.height // 2 - popup_height // 2
self.popup = Popup(popup_left, popup_bottom, popup_width, popup_height, self.ui_manager)
self.section_manager.add_section(self.popup)
def on_draw(self):
arcade.start_render()
def main():
window = arcade.Window(width=800, height=600, title='title')
game_view = GameView()
window.show_view(game_view)
window.run()
if __name__ == "__main__":
main()
I also tries to create the GUImanager in the gameView and pass it to the section through an argument, it doesn't change anything.
I looked at the "Sections Demo 3" example on the Arcade website, but it's not using Arcade GUI buttons.