为什么我的矩形不显示python 3.8 windoes 7

问题描述

我尝试复制游戏,但矩形(这是我需要的基本形状)没有出现。我做错了什么还是只是 pygame 发疯了?

代码

# importing modules
import pygame
import sys
import random

# starting pygame
pygame.init()
# making a screen
(width,height) = (500,500)
screen = pygame.display.set_mode((width,height))
pygame.display.set_caption('Mincraft')
running = True
# fps counter
clock = pygame.time.Clock()
print(clock)
# geting the x button to work
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
            pygame.display.update()
pygame.display.quit()
pygame.quit()
exit()
# colors
white = (255,255,255)
blue = (0,255)
red = (255,0)
green = (4,0)

# cube
if running == True:
    pygame.draw.rect(screen,blue,(395,10,10)),pygame.draw.rect(screen,20,clock.tick(60)

还有我将如何使它成为空的和 3d 的。我知道我要求很多,但我相信有人可以解释

解决方法

您必须在应用程序循环中绘制场景:

# importing modules
import pygame
import sys
import random

# colors
white = (255,255,255)
blue = (0,255)
red = (255,0)
green = (4,0)

# starting pygame
pygame.init()
# making a screen
(width,height) = (500,500)
screen = pygame.display.set_mode((width,height))
pygame.display.set_caption('Mincraft')
running = True
# fps counter
clock = pygame.time.Clock()
print(clock)
# geting the x button to work
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
            
    pygame.draw.rect(screen,blue,(395,10,10))
    pygame.draw.rect(screen,20,10))
    pygame.display.update()
    clock.tick(60)

pygame.display.quit()
pygame.quit()
exit()

典型的 PyGame 应用程序循环必须: