可以在Kivy中的图像圆形边缘吗?

发布于 2025-01-30 09:21:45 字数 322 浏览 1 评论 0原文

我对我的代码有疑问,找不到任何答案,所以我来了。有人知道是否可以在Kivy中绕过图像的边缘吗?我不是指舍入按钮的边缘。

我的图像代码:

    Image:
        source: 'assets/images/banner/purple.jpeg'
        keep_ratio: True
        height: 250
        width: 350
        center_x: root.width / 2
        center_y: 575

PS尝试使用边框属性。没有错误,但图像也没有变化:(

I had a question about my code and couldn't find any answers so I came here. Does anyone know if it is possible to round the edges of an image in kivy and how? I am not referring to rounding a button's edges.

My image code:

    Image:
        source: 'assets/images/banner/purple.jpeg'
        keep_ratio: True
        height: 250
        width: 350
        center_x: root.width / 2
        center_y: 575

P.S. Tried using the border property. No errors but no change in the image either :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心不设防 2025-02-06 09:21:45

在这种情况下,最好的解决方案是用椭圆形成画布:

kivy doc:

.kv

canvas:
        Color:
            rgb: 1, 1, 1
        Ellipse:
            pos: 100, 100
            size: 200, 200
            source: 'assets/images/banner/purple.jpeg'
            angle_start: 0
            angle_end: 360

我也建议您查看

动态类:
https://kivy.org/doc/doc/stable/stable/api--kivy.lang。 html

导入,设置并包括:
https://kivy.org/doc/doc/stable/guide/guide/guide/lang.htm.html.html

这将帮助您保持主KV文件尽可能小。因此,您也有变量,例如文本颜色和内容,因此您只需要在一个地方进行更改即可。

希望它有帮助

In this case the best solution would be to do a canvas with a Ellipse:

kivy doc:
https://kivy.org/doc/stable/examples/gen__canvas__circle__py.html

.kv

canvas:
        Color:
            rgb: 1, 1, 1
        Ellipse:
            pos: 100, 100
            size: 200, 200
            source: 'assets/images/banner/purple.jpeg'
            angle_start: 0
            angle_end: 360

I would suggest also looking at

Dynamic Classes:
https://kivy.org/doc/stable/api-kivy.lang.html

import, set and include :
https://kivy.org/doc/stable/guide/lang.html

this would help you keep your main kv file as small as possible. And also so you have variables for example text colors and stuff so you only need to change in one place.

Hope it helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文