Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a simple way to add a border to Kivy Buttons

I am using python-2.7 and kivy. Can someone tell me that how to add a different colour border to kivy button.

test.py

from kivy.uix.screenmanager import Screen
from kivy.app import App
from kivy.core.window import Window

Window.clearcolor = (0.5, 0.5, 0.5, 1)
Window.size = (300, 100)


class User(Screen):
    pass


class Test(App):

    def build(self):
        return self.root


if __name__ == '__main__':
    Test().run()

test.py

User:
    BoxLayout:

        Button:
            background_normal: ''
            text: 'Ok'
like image 269
Nirdesh Kumawat Avatar asked Sep 13 '18 09:09

Nirdesh Kumawat


2 Answers

I suppose you mean additionnaly to the current background/border.

If so, you probably want to use some canvas instruction.

You probably want to add them in canvas.before so it's drawn before the text of the button.

The instruction you'll use will depend on the effect you want, but Line is probably a good start.

Button:
    text: 'test'
    canvas.before:
        Color:
            rgba: .5, .5, .5, 1
        Line:
            width: 2
            rectangle: self.x, self.y, self.width, self.height
like image 174
Tshirtman Avatar answered Oct 16 '22 12:10

Tshirtman


You may want to look at the border property of the Button Class,basically: In kiv:

Button:
        border: (10,10,10,10)

I believe this will be the border image used by BorderImage

Disclaimer: Not tested but its along those lines

like image 22
silverhash Avatar answered Oct 16 '22 11:10

silverhash