python - 带有圆角的 Pygame 按钮,border_radius 参数不起作用

标签 python pygame rounded-corners rect

我目前正在学习pygame。在编写带有圆角的矩形时,我遇到了一个问题。

pygame.draw.rect() draw a rectangle 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 Draws a rectangle on the given surface.

border_radius (int) -- (optional) used for drawing rectangle with rounded corners. The supported range is [0, min(height, width) / 2], with 0 representing a rectangle without rounded corners.



这是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)

如果您能帮助我,我将非常高兴,在此先感谢您!

最佳答案

该文档适用于 2.0.0.dev7,根据 this PR , border_radius在 2.0.0.dev6 之后添加,GitHub reference ,被释放。所以你正在尝试使用尚未出现的东西。您可以尝试从源代码构建并使用关键字(尽管稳定性不是保证)。或者您可以尝试使用矩形和圆形的组合来实现效果。

关于python - 带有圆角的 Pygame 按钮,border_radius 参数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61523241/

相关文章:

python - 从 value.counts() 创建一个新的数据框

python - 如何在 django-rest-framework 中为 API 使用 TokenAuthentication

python - pygame Sprite 和绘制方法未按预期工作

python - 有没有办法完全阻止用户退出 pygame 窗口?

iphone - iOS Sim中的圆角而不是iPhone中的圆角

image - 如何为图像控件设置圆角?

python - networkx 中具有 'key' 个节点可访问的最短路径

python - 无法在 mac 上的 python 中导入 mysqldb

python - Pygame 在全屏模式下不返回鼠标位置

css - 网站周围的圆 Angular 边框