|
1鱼币
安装了pygame,import pygame 也没有报错。不过有一点,pygame是64位的,我的python版本是32位的。
这是我打的第一段,能出现pygame窗口,但无法点x关闭,改变颜色。
import sys
import pygame
def run_game():
#初始化游戏并创建一个屏幕对象
pygame.init()#初始化背景设置
screen = pygame.display.set_mode((1200,800))#调用pygame.display.set_mode创建screen的窗口,实参是一个元祖
pygame.display.set_caption("Alien Invasion")
#设置背景色
bg_color = (230,230,230)
#开始游戏的主循环
while True:
#监视键盘和鼠标事件
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()#这里点x就能调用然后关闭
#每次循环时都重绘屏幕
screen.file(bg_color)
#让最近绘制的屏幕可见
pygame.display.flip()
run_game()
这是底下的报错
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "C:\Users\acer\Desktop\python_work\武装飞船\alien_invasion.py", line 30, in <module>
run_game()关键的东西好像都没识别
File "C:\Users\acer\Desktop\python_work\武装飞船\alien_invasion.py", line 24, in run_game
screen.file(bg_color)
AttributeError: 'pygame.Surface' object has no attribute 'file'
|
最佳答案
查看完整内容
写错了吧
https://www.cnblogs.com/liuhaier/p/8947522.html
|