python - 树莓派和 Pygame 菜单
问题描述
我想在树莓派中使用名为 pygame-menu 的 python 库,因为我想和其他人一起开发游戏。我测试了他们的一个演示,我得到了以下错误:
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "/home/pi/Pandemic/GameDev.py", line 2, in <module>
import pygame_menu
File "/home/pi/.local/lib/python3.7/site-packages/pygame_menu/__init__.py", line 66, in <module>
import pygame_menu.themes
File "/home/pi/.local/lib/python3.7/site-packages/pygame_menu/themes.py", line 386, in <module>
THEME_DEFAULT = Theme()
File "/home/pi/.local/lib/python3.7/site-packages/pygame_menu/themes.py", line 198, in __init__
bool, pygame.vernum.major == 2) # type: bool
AttributeError: 'tuple' object has no attribute 'major'
这也是我的代码:
import pygame
import pygame_menu
pygame.init()
surface = pygame.display.set_mode((600, 400))
def set_difficulty(value, difficulty):
# Do the job here !
pass
def start_the_game():
# Do the job here !
pass
menu = pygame_menu.Menu(300, 400, 'Welcome',
theme=pygame_menu.themes.THEME_SOLARIZED)
menu.add_text_input('Name :', default='John Doe')
menu.add_selector('Difficulty :', [('Hard', 1), ('Easy', 2)], onchange=set_difficulty)
menu.add_button('Play', start_the_game)
menu.add_button('Quit', pygame_menu.events.EXIT)
menu.mainloop(surface)
你能帮我修一下吗?我和 Thonny 一起运行了这个程序
解决方案
我已经修好了。事实证明,树莓派的 pygame 的默认版本是 1.9.4,而 pygame-menu 需要 1.9.6 及更高版本,所以我使用以下命令对其进行了升级:
python3 -m pip install -U pygame --user
推荐阅读
- linux - 集成 VSCode(代码 - OSS)终端中的口音
- python - Python Pandas read_csv function does not allow to change parsed dates into required format
- haskell - 递归显然有非详尽的模式
- javascript - How to set optional date? : Milliseconds to date
- sql - sql:如何使用动态列制作数据透视表
- vue.js - Vue:如何在现有的 SPA 项目中启用多页面?
- java - 检查 Thymeleaf 页面中的对象上是否存在特定字段
- c++ - 带有指针和递归的随机崩溃
- r - Plotly R:具有0 y轴值的值的悬停文本
- networking - 用于流量委托的 Kubernetes 概念或类似的东西?