python - 按钮类错误:'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)
解决方案
推荐阅读
- android - 标签出现在 Android 模拟器中,但不在物理设备上
- java - Hive - 检索分区和文件位置的最快方法
- jenkins - java.lang.UnsupportedOperationException:没有已知的 jenkins.tasks.SimpleBuildWrapper 类实现在 jenkins 中被命名为 BuildUser
- python - 在 python 中使用 OpenCVs VideoStream 时是否可以调用函数来执行 MySQL 命令?
- sql-server - SQLAlchemy 没有与外键中的引用列列表匹配的主键或候选键
- python - 将价格计算器添加到列表中
- firebase - 拒绝元数据:准则 2.1 - 所需信息
- php - 如何自定义条带订阅支付描述字段
- javascript - 箭头函数中的组件重新渲染
- r - 如何使用 API(使用 R & httr)