该游戏预 进入游戏时显示一个图片,通过点击该图片可以调用该游戏主代码,运行游戏。
希望代码解释
# 初始化按钮坐标范围
coo = list()
# 循环每一个按钮图像,进行按钮图像绘制及坐标范围获取
for i in range(len(button_images)):
coo.append(self.menu(button_images[i], i + 4))
# 依据鼠标位置与按钮坐标范围判断鼠标是否与按钮碰撞并点击,如果是,分别对相应按钮坐标点击事件进行标记
if (coo[0][0][0] <= round(cursor_x - cursor.get_width() / 2) <= coo[0][1][0] and
coo[0][0][1] <= round(cursor_y - cursor.get_height() / 2) <= coo[0][1][1]):
self.menu(button_images[0], 0 + 4)
if is_click:
choice = 1
if (coo[1][0][0] <= round(cursor_x - cursor.get_width() / 2) <= coo[1][1][0] and
coo[1][0][1] <= round(cursor_y - cursor.get_height() / 2) <= coo[1][1][1]):
self.menu(button_images[1], 1 + 4)
if is_click:
choice = 2
if (coo[2][0][0] <= round(cursor_x - cursor.get_width() / 2) <= coo[2][1][0] and
coo[2][0][1] <= round(cursor_y - cursor.get_height() / 2) <= coo[2][1][1]):
self.menu(button_images[2], 2 + 4)
if is_click:
choice = 3
记录下图片的左上和右下两个点的坐标,在这两个点之间的坐标都是图片范围。判断鼠标坐标是否在该范围内,然后判断点击事件是否发生,都满足则调用主程序文件就OK啦。
才看到这个问题是13年的,不知道楼主有没有更好的方法解决了这个问题。