PRADDYUMN YADAV
PRADDYUMN YADAV

Reputation: 11

How to Use Rounded Buttons in Kivy With all Functionalities of Regular Button

How to Add Rounded Buttons in Kivy . I Want to Make My Buttons Rounded in Kivy I Have Done This By Using Canvas But The Problem is That If I Click on The Buttons There is No Animation Present I The Click

main.kv File

<Button>:
    font_size : 32
    background_normal : ""
    background_color : (1,0,0,1)
<MyLayout>:
    BoxLayout:
        orientation: 'vertical'
        size : root.width, root.height
        spacing: 20
        padding : 50
        Button:
            text:'Hello World!'
        RoundedButton:
            text:'Goodbye World!'
            pos_hint : {"center_x":0.5}
            size_hint : (1, .3)

<RoundedButton@Button>
    background_color : (0,0,0,0)
    background_normal : ""
    canvas.before:
        Color:
            rgba : (0, 0, 1, 1)
        RoundedRectangle:
            size : self.size
            pos : self.pos
            radius : [58]

main.py file

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.widget import Widget
from kivy.core.window import Window
Builder.load_file("rbuttons.kv")

class MyLayout(Widget):
    pass

class RButtonsApp(App):
    def build(self):
        Window.clearcolor = (1,1,1,1)
        return MyLayout()

if __name__ == "__main__":
    RButtonsApp().run()

Upvotes: 1

Views: 643

Answers (1)

John Anderson
John Anderson

Reputation: 38937

If you are just talking about the color change when you press the RoundedButton, you can just modify the rgba in the <RoundedButton@Button>:

rgba : (0, 0, 1, 1) if self.state == 'normal' else (1, 0, 0, 1)

Upvotes: 1

Related Questions