【发布时间】:2021-01-08 22:52:52
【问题描述】:
每当我尝试运行event.type == pygame.QUIT,event.type == QUIT
或 event.type == pygame.quit() 在我的 pygame 程序中,我收到一条错误消息,指出 Module 'pygame' has no 'QUIT' member 或 Undefined variable 'QUIT'。当我运行程序时,它打开得很好,但是当我关闭 pygame 窗口时,它完全崩溃并且没有关闭。
我尝试重新安装 pygame,但没有成功。看起来 pygame 包没有任何形式的退出功能,即使像 Clock() 和 display() 这样的其他功能也在那里。我认为这可能与安装问题有关,但我不知道如何以简洁的方式解决。
这是我的代码:
import pygame, sys
from pygame.locals import *
from sys import exit
import os
from moves import Moves
from moves import *
from character import Character
from items import Items
import random
import pandas as pd
from pokemon import Pokemon
...
running = True
FPS = 60
clock = pygame.time.Clock()
while running:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == QUIT:
running=False
【问题讨论】:
-
你能发布你的代码吗?
-
也许你用代码中的某些东西覆盖了
pygame?这只是一个疯狂的猜测,因为如果没有看到您的代码,实际上是不可能提供帮助的。请发minimal reproducible example。 -
通过 pip 重新安装 pygame 很可能会安装相同的,因为它被缓存了。不久前我遇到了同样的问题。尝试使用
pip install --no-cache-dir < pygame >。也看看this -
@hippozhipos,我尝试了 pip install 命令,它说要求已经满足,我应该这样卸载并重新安装吗?
-
更新代码@BWallDev