我正在尝试在 pygame 中绘制一个带有圆边的空心矩形,这是我的代码:
pygame.draw.rect(screen,(0,0,0),(350,400,200,100),5,5)
它说“TypeError 函数最多接受 4 个参数(给定 5 个)”。 我想知道它是否与我使用的 pygame 版本有关,我有 pygame 1.9.6。我查看了 pygame 文档,它说我最多可以使用 9 个参数。
最佳答案
border_radius
参数仅添加到 PyGame 版本 2.0.0.dev8
。
如果您使用的是旧版本的 PyGame,可以通过在角上画圆来执行此操作:
def drawRoundedRect( screen, rect, colour=(128,128,128), radius=7 ):
x, y = rect.topleft
width = rect.width
height = rect.height
pygame.draw.circle( screen, colour, ( x+radius, y+radius ), radius ) # TL corner
pygame.draw.circle( screen, colour, ( x+width-radius-1, y+radius ), radius ) # TR corner
pygame.draw.circle( screen, colour, ( x+radius, y+height-radius-1 ), radius ) # BL corner
pygame.draw.circle( screen, colour, ( x+width-radius-1, y+height-radius-1 ), radius ) # BR corner
# In-fill
pygame.draw.rect( screen, colour, ( x+radius, y, width-(2*radius), height ) )
pygame.draw.rect( screen, colour, ( x, y+radius, width, height-(2*radius) ) )
关于python - pygame.draw.rect() 参数太多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63185116/