简体   繁体   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()

It's supposed to show a retangle in a 640x360 window, and it doesn't do that, and I don't know why it doesn't do that.它应该在 640x360 的窗口中显示一个 retangle,但它没有这样做,我不知道为什么它不这样做。 Please help me.请帮我。

It works like that:它是这样工作的:

在此处输入图片说明

You may be expected to behave differently?你可能会有不同的表现?

The following code works for me well.以下代码对我很有效。

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

Though if you are facing any error, please share the error.但是,如果您遇到任何错误,请分享错误。

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

相关问题 在 python 上需要帮助。 我不知道为什么它不起作用 - Need help on python. I don't know why it doesn't work Java 程序不像 python 程序那样工作,我不知道为什么 - Java program doesn't work like python program and I don't know why 我不知道为什么这个 for 循环程序不起作用(python)。 解决方案? - I don't know why this for loop program doesn't work (python). Solutions? 我的gridsearchCV不起作用,我也不知道为什么 - My gridsearchCV don't work and i don't know why 我正在创建密码生成器,但我不知道为什么它不起作用 - I'm creating a password generator but I don't know why it doesn't work 对 Python 编程有点陌生,正在尝试一个问题。 我只是不知道为什么这个错误不断弹出。 对我来说真的没有意义 - Kinda new to Python Programming and was attempting a question. I just don't know why this error keeps popping up. Really doesn't make sense to me 我的 if else 输入循环不起作用,我不知道为什么 - My if else loop for an input doesn't work and I don't know why For循环python(初学者):不知道为什么这行不通 - For loops python (beginner): Don't know why this won't work 这不会产生窗口,我不知道为什么 - This doesn't produce a window and I don't know why Python 代码无法运行,我不知道如何修复它 - Python code doesn't run, I don't know what to do to fix it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM