问题描述
我对 python 非常陌生,我一直在关注 Tech With Tim 的 pygame 教程,但我的窗口没有响应或关闭。我使用的是 mac,我不知道这是否会改变任何东西......而且我不断收到错误消息
错误:
function missing required argument 'rect' (pos 3)
。
代码:
import pygame
pygame.init()
win = pygame.display.set_mode((500,500))
pygame.display.set_caption("First game")
x = 50
y = 50
width = 40
height = 60
vel = 5
run = True
while run:
pygame.time.delay(100)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
x -= vel
if keys[pygame.K_RIGHT]:
x += vel
if keys[pygame.K_UP]:
y -= vel
if keys[pygame.K_DOWN]:
y += vel
pygame.draw.rect(win,(255,0))
pygame.display.update()
pygame.quit()
解决方法
rect
函数至少接受三个参数,只给出了 2 个:
pygame.draw.rect(win,(255,0),(x,y,width,height))
它应该也适用于 mac
查看 pygame 文档以供参考:https://www.pygame.org/docs/ref/draw.html#pygame.draw.rect
,实际上您还没有输入绘制矩形的高度宽度 x 位置和 y 位置,请执行此操作
{
"Version": "2012-10-17","Statement": [
{
"Effect": "Allow","Action": [
"logs:CreateLogGroup","logs:CreateLogStream","logs:PutLogEvents"
],"Resource": "arn:aws:logs:*:*:*"
},{
"Effect": "Allow","Action": [
"ec2:DescribeSecurityGroups","ec2:AuthorizeSecurityGroupIngress","ec2:RevokeSecurityGroupIngress"
],"Resource": "*"
}
]
}
您已经定义了 pygame.draw.rect(win,height,width))
、x
、y
、height
这应该可以工作。