带有圆角的 Pygame 按钮,border_radius 参数不起作用 [英] Pygame Button with rounded Corners, border_radius argument does not work

查看:67
本文介绍了带有圆角的 Pygame 按钮,border_radius 参数不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am currently learning pygame. When programming rectangles with rounded corners I encountered a problem.

pygame.draw.rect()画一个矩形矩形(表面,颜色,矩形)-> 矩形rect(表面,颜色,矩形,宽度=0,border_radius=0,border_radius=-1,border_top_left_radius=-1,border_top_right_radius=-1,border_bottom_left_radius=-1)->矩形在给定的表面上绘制一个矩形.

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) --(可选)用于绘制圆角矩形.支持的范围是[0, min(height, width)/2],0代表没有圆角的矩形.

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官方文档的说明.

This is the description of the official pygame documentation.

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)

这里是主要部分.但后来我收到此错误消息:

Here the main part. But then I get this error message:

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)

I already tried to add a "width=2" argument but then it says that there are too many arguments. Unfortunately taking other numbers does not help either. I am currently using pygame version 2.0.0.dev6 (SDL 2.0.10, python 3.8.1)

如果你能帮助我,我会很高兴,先谢谢了!

I would be very happy if you could help me, thanks a lot in advance!

推荐答案

文档适用于 2.0.0.dev7,根据 这个 PRborder_radius 是在 2.0.0.dev6 之后添加的,GitHub 参考,已发布.所以你正在尝试使用尚未出现的东西.您可以尝试从源代码构建并使用关键字(尽管稳定性不是保证).或者您可以尝试使用矩形和圆形的组合来达到效果.

The documentation is for 2.0.0.dev7, and according to this PR, border_radius was added after 2.0.0.dev6, GitHub reference, was released. So you're trying to use something that hasn't come out yet. You could try building from source and using the keyword (though stability is not a promise). Or you could try using a combination of rectangles and circles to achieve the effect.

这篇关于带有圆角的 Pygame 按钮,border_radius 参数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆