小编Sam*_*mmy的帖子

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

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

我在 arcade.academy 上查找了有关如何在街机中使用按钮的教程,但它需要使用街机形状手动绘制形状和输入文本。我还尝试了一个教程,将坐标输出到 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, …
Run Code Online (Sandbox Code Playgroud)

python module button arcade

5
推荐指数
1
解决办法
1148
查看次数

标签 统计

arcade ×1

button ×1

module ×1

python ×1