Rounding button corners in kivy

前端 未结 2 1158
花落未央
花落未央 2020-12-25 13:44

What is the preferred way to create rounded corners for buttons in kivy?

Are there other equally viable ways to perform this task? Thank you.

2条回答
  •  梦谈多话
    2020-12-25 14:41

    If you are looking only for good looks, and aren't picky about the corners, though rounded, are still touch points, you can do it simply, as shown in this sample program (This has large radius for this sample):

    from kivy.uix.button import Button
    from kivy.lang import Builder
    from kivy.base import runTouchApp
    
    kv="""
    :
        background_color: 0,0,0,0  # the last zero is the critical on, make invisible
        canvas.before:
            Color:
                rgba: (.4,.4,.4,1) if self.state=='normal' else (0,.7,.7,1)  # visual feedback of press
            RoundedRectangle:
                pos: self.pos
                size: self.size
                radius: [50,]
    """
    class RoundedButton(Button):
        pass
    
    Builder.load_string(kv)
    
    runTouchApp(RoundedButton(text="Hit Me!"))
    

提交回复
热议问题