首页 > 解决方案 > 按钮类错误:'button_list not defined'... 使用 replit

问题描述

我正在按照在线教程为平台游戏创建地图编辑器,但我的导入按钮功能不起作用,显示错误“button_list not defined”,但我不明白为什么这是因为我已经将其定义为空列表。它运行代码,直到我将 draw 方法放在底部,然后它抛出这个错误......

import pygame
import button

def button():
    button_list = []
    button_col = 0
    button_row = 0
    for i in range(len(img_list)):
        tile_button = button.Button(SCREEN_WIDTH + (75 * button_col) + 50, 75 * button_row + 50, img_list[i], 1)
        button_list.append(tile_button)
        button_col += 1
        if button_col == 3:
            button_row += 1
            button_col = 0

for i in button_list:
    i.draw(screen)

标签: pythonpython-3.xbuttonpygame

解决方案


推荐阅读