2013-04-28 89 views
-3
import pygame, sys 
from pygame.locals import * 

pygame.init() 
screen=pygame.display.set_mode((640,360),0,32) 

while True:  
    for event in pygame.event.get():   
     if event.type == QUIT:   
      pygame.quit()   
      sys.exit()   
     screen.lock()   
     pygame.draw.rect(screen, (140,240,130), Rect((100,100),(130,170))) 
     screen.unlock()  
     pygame.display.update() 

它应该显示在640x360的窗口retangle,它不这样做,我不知道为什么它不去做。请帮帮我。我不知道为什么会这样Python编程代码不起作用

+6

如果您在帖子中修复了缩进,它会澄清事情。 – nobar 2013-04-28 06:03:17

+1

它是做什么的?你有错误吗? – Cfreak 2013-04-28 06:03:19

+2

请正确格式化此代码!缩进级别会显着改变代码的行为,即调用嵌套在if event.type == QUIT中的'pygame.draw'和'pygame.display'?如果是这样,然后pygame/python将退出,然后您可以绘制任何东西。 – HennyH 2013-04-28 06:11:50

回答

0

以下代码适合我。

#!/usr/bin/python 

import pygame, sys 
from pygame.locals import * 
pygame.init() 
screen = pygame.display.set_mode((640,360),0,32) 
while True: 
    for event in pygame.event.get(): 
     if event.type == QUIT: 
      pygame.quit() 
      sys.exit() 
      screen.lock() 
      pygame.draw.rect(screen, (140,240,130), Rect((100,100),(130,170))) 
      screen.unlock()  
pygame.display.update() 

虽然如果您面临任何错误,请分享错误。

2

它的工作原理类似:

enter image description here

您可以预期不同的表现?

相关问题