You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python Arcade框架中Section内UI按钮无响应问题求助

Arcade Section中添加的Arcade.gui按钮无响应(无法触发悬停/点击)

您好,这是我首次在Stack Overflow发帖,若内容有不当之处敬请谅解。

我正在使用Python的Arcade与Arcade.gui库,尝试在Section实例(命名为popup)中添加GUI组件。按钮可正常显示,但存在无响应问题:无法触发悬停或点击效果(图片与源码同目录)。

我曾尝试在GameView中创建UIManager并传入Section,问题仍未解决;也参考了Arcade官网的“Sections Demo 3”示例,但该示例未使用Arcade GUI按钮。

以下是我的最小复现代码:

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()

内容的提问来源于stack exchange,提问作者Duchemin74

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 11:58:12