Is there a simple way to add a border to Kivy Labels, Buttons, Widgets etc. with-out images?

僤鯓⒐⒋嵵緔 提交于 2019-12-22 07:48:12

问题


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.

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.

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.)

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

Here is how it looks at the moment:

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


回答1:


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

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.

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:

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.



来源:https://stackoverflow.com/questions/23943822/is-there-a-simple-way-to-add-a-border-to-kivy-labels-buttons-widgets-etc-with

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!