新手求帮助

SWXG00 2017-03-13 04:19:29
import sys
import pygame
def run_game():
pygame.init()
screen=pygame.display.set_mode((1200,800))
pygame.display.set_caption("Alien Invasion")
while True:
for event in pygame.event.get():
if event.type==pygame.QUIT:
sys.exit()
pygame.display.flip()
run_game()




这是看着书做的一个 小游戏窗口的代码

但是运行一直显示
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\python\00\aline_invasion.py", line 8, in <module>
for event in pygame.event.get():
pygame.error: video system not initialized



运行环境win7 python3.6
...全文
196 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
python_lele 2017-03-16
  • 打赏
  • 举报
回复
完全正确!~~~ import sys import pygame def run_game(): pygame.init() screen=pygame.display.set_mode((1200,800)) pygame.display.set_caption("Alien Invasion") if __name__=='__mian__': for event in pygame.event.get(): if event.type==pygame.QUIT: sys.exit() pygame.display.flip() run_game()
sanGuo_uu 2017-03-13
  • 打赏
  • 举报
回复
# -*- coding:utf-8 -*-

import sys
import pygame
def run_game():
	pygame.init()
	screen=pygame.display.set_mode((1200,800))
	pygame.display.set_caption("Alien Invasion")
	
	while True:
		for event in pygame.event.get():
			if event.type==pygame.QUIT:
				sys.exit()
	pygame.display.flip()

run_game()
没报错

37,722

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧