Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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: Screenshot of border demo app

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

like image 877
AWolf Avatar asked May 29 '14 22:05

AWolf


People also ask

What is Self in KIVY?

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 .


1 Answers

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: Screenshot of Button with border

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.

like image 83
AWolf Avatar answered Sep 21 '22 09:09

AWolf