繁体   English   中英

我不知道为什么这个 Python 编程代码不起作用

[英]I don't know why this Python Programming code doesn't work

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,但它没有这样做,我不知道为什么它不这样做。 请帮我。

它是这样工作的:

在此处输入图片说明

你可能会有不同的表现?

以下代码对我很有效。

#!/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()

但是,如果您遇到任何错误,请分享错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM