在Python中,如何使用arcade中的图像制作交互式按钮?

在Python中,如何使用arcade中的图像制作交互式按钮?,python,button,module,Python,Button,Module,我正在尝试使用python在arcade中创建一个交互式按钮。我正在使用操作系统导入图像,不知道是否可以将单击功能转换为图像。我希望通过点击图片打开一个新窗口。我知道tkinter主要用于此,但我正在创建一个游戏,不想使用tkinter。我也不喜欢使用PyGame。我也不知道如何在从操作系统导入的图像上应用边界 我在arcade.academy上查阅了一篇关于如何在arcade中使用按钮的教程,但它需要使用aracade形状手工绘制形状和输入文本。我还尝试了一个教程,在单击画布上的随机点时将坐标

我正在尝试使用python在arcade中创建一个交互式按钮。我正在使用操作系统导入图像,不知道是否可以将单击功能转换为图像。我希望通过点击图片打开一个新窗口。我知道tkinter主要用于此,但我正在创建一个游戏,不想使用tkinter。我也不喜欢使用PyGame。我也不知道如何在从操作系统导入的图像上应用边界

我在arcade.academy上查阅了一篇关于如何在arcade中使用按钮的教程,但它需要使用aracade形状手工绘制形状和输入文本。我还尝试了一个教程,在单击画布上的随机点时将坐标输出到python shell中,尝试将其合并到图像中。下面的示例代码尚未完成,但我已经尝试过这样做

import arcade
import os
SCREEN_WIDTH = 700
SCREEN_HEIGHT = 700
class MyGame(arcade.Window):
    def __init__(self):
        super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, "sprites")
        file_path = os.path.dirname(os.path.abspath(__file__))
        os.chdir(file_path)
        self.player_list = None
        self.player_sprite = None
        self.set_mouse_visible(True)
        self.pressed = (False)
        arcade.set_background_color(arcade.color.AMAZON)
    def Button(self, center_x, center_y, action_function):
        self.player_list = arcade.SpriteList()
        self.player_sprite = arcade.Sprite("osss.png", 0.5)
        self.player_sprite.center_x = center_x
        center_x = 50
        self.player_sprite.center_y = center_y
        center_y = 50
        self.player_list.append(self.player_sprite)
        self.action_function = action_function

    def on_draw(self):
        arcade.start_render()
        self.player_list.draw()
    def on_mouse_motion(self, x, y, dx, dy):
        self.player_sprite.center_x = x
        self.player_sprite.center_y = y
    def update(self, delta_time):
        x = self.center_x
        y = self.center_y
        if not self.pressed:
            x -= self.Button_height
            y += self.Button_height

    def on_press(self):
        self.pressed = True

    def on_release(self):
        self.pressed = False

    def check_mouse_press_for_buttons(x, y, self): #Button.on_press()
        for button in self.player_list:
            if x > button.center_x + button.width / 2:
                continue
            if x < button.center_x - button.width / 2:
                continue
            if y > button.center_y + button.height / 2:
                continue
            if y < button.center_y - button.height / 2: 
                continue
        def check_mouse_release_for_buttons(x, y, dx, dy, button_list):  #make the action happen
            for button in button_list:
                if button.pressed:
                    button.on_release()
                    arcade.draw_randomrect_filled(x, y, dx, dy, arcade.color.PINK)

    def on_release(self):
        super().on_release()
        self.action_function()


def main():
    window = MyGame()
    window.Button(center_x, center_y, action_function)
    arcade.run()
if __name__ == "__main__":
   main()
导入arcade
导入操作系统
屏幕宽度=700
屏幕高度=700
类MyGame(街机窗口):
定义初始化(自):
超级()
file_path=os.path.dirname(os.path.abspath(uu file_uu))
chdir(文件路径)
self.player\u list=无
self.player\u sprite=无
self.set\u鼠标\u可见(True)
self.pressed=(False)
arcade.set_background_color(arcade.color.AMAZON)
def按钮(自我、居中x、居中y、动作功能):
self.player_list=arcade.SpriteList()
self.player_sprite=arcade.sprite(“osss.png”,0.5)
self.player\u sprite.center\u x=center\u x
中心x=50
self.player\u sprite.center\u y=center\u y
中心y=50
self.player\u list.append(self.player\u精灵)
self.action\u函数=action\u函数
def on_牵引(自):
arcade.start_render()
self.player_list.draw()
鼠标运动时的def(自身、x、y、dx、dy):
self.player\u sprite.center\u x=x
self.player\u sprite.center\u y=y
def更新(自身、增量时间):
x=自中心
y=自中心
如果不是自动按下:
x-=自身按钮高度
y+=自身按钮高度
def on_按下(自):
self.pressed=True
def on_释放(自):
self.pressed=False
def检查鼠标按下按钮(x,y,self):#按钮。打开按钮()
对于self.player_列表中的按钮:
如果x>button.center\u x+button.width/2:
持续
如果xbutton.center\u y+button.height/2:
持续
如果y
我确实收到了很多“未定义”的错误消息。我并没有很好地分配我的价值观。我也期待着被拒绝,很多人告诉我这是不可能的