简体   繁体   中英

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'

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

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

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