有没有简单的方法可以在没有图像的情况下为Kivy标签,按钮,小部件等添加边框? [英] Is there a simple way to add a border to Kivy Labels, Buttons, Widgets etc. with-out images?

查看:93
本文介绍了有没有简单的方法可以在没有图像的情况下为Kivy标签,按钮,小部件等添加边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向Kivy Buttons添加边框,但是它没有按预期工作. 对于标签,我的实现似乎可以,但是对于按钮,它可以覆盖/清除按钮的标准外观.

I'm trying to add a border to Kivy Buttons but it doesn't work as expected. For labels my implementation seems to be OK but for buttons it overrides/clears the standard look of the button.

如何在不更改正常行为的情况下在按钮上方绘制边框?我想像ButtonBehavior一样实现它,以便可以使用画布为每个Kivy对象添加边框.我称它为BorderBehavior.

How can I draw the border above the button with-out changing normal behavior? I'd like to implement it like the ButtonBehavior so I can add a border to every Kivy object with a canvas. I've called it BorderBehavior.

虚线,点线样式仅适用于线宽1,因为Kivy中存在错误(请参见 https://github.com/kivy/kivy/issues/2037 )(需要稍后在这里找出问题所在.)

Styling dashed, dotted works only for line width of 1 because there is a bug in Kivy (see https://github.com/kivy/kivy/issues/2037) (Need to figure out what's wrong here later.)

我知道可以使用BorderImage绘制边框,但是我想添加没有图像的简单边框.

I know that drawing a border is possible with a BorderImage but I'd like to add simple borders with-out an image.

这是现在的样子:

您可以在此处找到我的源代码(可以拖动标签只是出于测试目的,以查看边框始终正确放置):

You can find my source code here (the labels can be dragged just for testing purposes to see that the border is always correctly positioned):

https://gist.github.com/AWolf81/c6796dc2049d9872b2df

推荐答案

好的,我已经找到了解决方法.这是一个命名冲突.

OK, I've found the fix. It was a naming conflict.

在控制台日志中,我看到在打开按钮的BorderImage中的边界元组时存在一个问题. 当然,这是行不通的,因为我的边界实施方式有所不同.也许我可以将列表(顶部,右侧,底部,左侧)添加到边框实现中,以便保持相同的名称.但是我还没有检查.

In the console log I saw that there is a problem at unpacking the border tuple in BorderImage of the button. Of course, that's not working because my border is implemented differently. Maybe I can add the list (top, right, bottom, left) to my border implementation so I can keep the same name. But I haven't checked that yet.

将我的边界命名更改为python和kv中的边界可解决此问题:

Changing the naming of my border to borders in python and in kv fixed the problem:

class BorderBehavior(Widget):
    borders = ObjectProperty(None)

现在看起来像我想要的:

Now it looks like I want it:

好的,现在我将检查它是否也适用于其他类(例如Scatter,Widget等).如果可以,我正在向Kivy发出拉动请求.

OK, now I'll check if it's working for other classes too (e.g. Scatter, Widget,...). If that's working I'm doing a pull request to Kivy.

这篇关于有没有简单的方法可以在没有图像的情况下为Kivy标签,按钮,小部件等添加边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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