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
self refers to current widget instance Rectangle. Rectangle is not a widget, it is a canvas instruction. self does refer to the current widget, which in your example is the PongGame .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With