Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 Python:PyGame绘制矩形帮助(初学者)_Python 2.7_Pygame - Fatal编程技术网

Python 2.7 Python:PyGame绘制矩形帮助(初学者)

Python 2.7 Python:PyGame绘制矩形帮助(初学者),python-2.7,pygame,Python 2.7,Pygame,我正在学习如何使用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 pyga

我正在学习如何使用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()   

你不需要锁定屏幕

问题是您没有在循环中绘制

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

你不需要锁定屏幕

问题是您没有在循环中绘制

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

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

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

相同,并不复杂。您需要做的只是:

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