python - 带有圆角的 Pygame 按钮,border_radius 参数不起作用
问题描述
我目前正在学习pygame。在对圆角矩形进行编程时,我遇到了一个问题。
pygame.draw.rect() 画一个矩形 rect(surface, color, rect) -> Rect rect(surface, color, rect, width=0,border_radius=0,border_radius=-1,border_top_left_radius=-1,border_top_right_radius=- 1、border_bottom_left_radius=-1) -> Rect 在给定的表面上绘制一个矩形。
border_radius (int) -- (可选)用于绘制圆角矩形。支持的范围是 [0, min(height, width) / 2],其中 0 表示没有圆角的矩形。
这是 pygame 官方文档的描述。
username_rect = pg.rect.Rect(screenwidth/2 - 1/8*screenwidth, screenheight*1/5, 1/4*screenwidth, username_title_render.get_height() + 10)
pg.draw.rect(screen, (0,0,0), username_rect,border_radius = 15)
这里是主要部分。但随后我收到此错误消息:
TypeError: 'border_radius' is an invalid keyword argument for this function
我已经尝试添加一个“width=2”参数,但它说参数太多。不幸的是,取其他数字也无济于事。我目前正在使用 pygame 版本 2.0.0.dev6(SDL 2.0.10,python 3.8.1)
如果您能帮助我,我将非常高兴,非常感谢您!