简体   繁体   中英

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

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

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: 带边框的Button的屏幕截图

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM