2013-11-24 293 views
0

这是我创建游戏的代码。当我尝试运行它时,它一直说名称“宽度”为 未定义。我对此很陌生,所以请在回答我的问题时尽量简单。谢谢:)Python NameError:name'width'is not defined

# 1 - Import library 
import pygame 
from pygame.locals import * 

# 2 - Initialize the game 
pygame.init() 
width, height - 640, 480 
screen-pygame.display.set_mode((width, height)) 

# 3 - Load Images 
player - pygame.images.load("resources/images/dude.png") 

# 4 - keep looping through 
while 1: 
    # 5 - clear the screen before drawing it again 
    screen.fill(0) 
    # 6 - draw the screen elements 
    screen.blit(player, (100,100)) 
    # 7 - update the screen 
    pygame.display.flip() 
    # 8 - loop through the events 
    for event in pygame.event.get(): 
     # check if the event is the X button 
     if event.type--pygame.QUIT: 
      # if it is quit the game 
      pygame.quit() 
      exit(0) 
+1

这个问题似乎是题外话,因为它是关于一个错字('-'而不是'=')。 – Doorknob

+2

作业是'=',而不是'-' –

+0

可能的'宽度,高度= 640,480'会有帮助吗? –

回答

2

width, height - 640, 480width, height = 640, 480

+0

谢谢soooo :) – user3027728

1

你写的 - 而不是=

还,不使用进口明星