Change color button in Kivy

1,326 views
Skip to first unread message

Fabien Eychenne

unread,
Jun 10, 2015, 10:27:38 AM6/10/15
to kivy-...@googlegroups.com

First of all i'm not a professional programmer i'm just an hobbyist using code to make some stuff to work (not always). I'm using Kivy at the moment to make a simple app and can't figure out how to change the color of a button to the color i really want. I've spent some time on the page, looked stackoverflow but still can't manage it... Here's a bit of code. I use background_color to change the color and i understood i should use background_normal to set the "white color" (but i don't want the rest to be white...) and i don't know where to change background_color... Same question for when it's pressed.

It's alright for Label, this works :)

Other other small question. To get my rgb i divided all the color by 255 to get a value between 0 and 1, is it the correct way or they could be something more precise? Thanks !


BoxLayout:
padding: 10
spacing: 10
orientation: 'vertical'
Label:
    text: "Jouer avec les verbes \nirréguliers par :"
    color: 1,1,1,1
    canvas.before:
        Color:
            rgba: 0.99, 0.65, 0.07, 1
        Rectangle:
            pos: self.pos
            size: self.size
BoxLayout:
    orientation: 'horizontal'
    spacing: 10

    Button:
        text: "L'infinitif"
        size_hint: 1, 1
        background_color: 0.81, 0.27, 0.33, 1

    Button:
        text: "La traduction \nFrançaise"
        size_hint: 1, 1

ZenCODE

unread,
Jun 11, 2015, 4:11:40 PM6/11/15
to kivy-...@googlegroups.com
Remember, the background_color only acts as a multiplier of the grey background, so it will always be "greyish". Fore example, the most "yellow" you will ever see is with:

    background_color: 1.0, 1.0, 0.0, 1

Your example work fine for me considering this.

If you want pure colours, I would suggest preparing images and using them for the 'background_down', 'background_normal' images etc. You could also create you own button composed of a label and image/layout, but that's a bit more work and probabaly not necessary...

re: rgb. Dividing by 255 (255.0) is spot on :-)
Reply all
Reply to author
Forward
0 new messages