0

我只是在学习如何使用Pygame,但是当我运行程序时,Pygame 窗口只是黑色并且没有矩形?任何人都可以帮忙吗?

         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()   
4

2 回答 2

2

您无需锁定屏幕。

问题是您没有在循环中绘图。

     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.fill((255,255,255))        
         pygame.draw.rect (screen, (140,240,130), Rect((100,100), (130,170)))
         pygame.display.update()   
于 2013-07-07T19:56:08.223 回答
1

这并不复杂。您需要做的就是:

import pygame
pygame.init()
screen = pygame.display.set_mode((640, 320))
screen.fill((255,255,255))
pygame.draw.rect(screen, (140,240,130), (100, 100, 130, 170), 0)
pygame.display.flip()
run = True
while run:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False
pygame.quit()

pygame.display.flip()部分与pygame.display.update()

于 2014-04-26T17:10:16.590 回答