Spinner Color Problem ?

98 views
Skip to first unread message

Ayhan Celik

unread,
Nov 15, 2019, 3:50:11 AM11/15/19
to Kivy users support
How can I change spinners containers color ?
button color changes but dropdown menu color doesn't change?
I couldn't find a narrative here. : https://kivy.org/doc/stable/api-kivy.uix.spinner.html

Spinner:
    id:sp1
    text:"text1"
    size_hint: 1,0.5
    values:
         ["cont1","cont2","cont3","cont4"]
    background_color: 1,0,0,1

Elliot Garbus

unread,
Nov 15, 2019, 2:45:35 PM11/15/19
to kivy-...@googlegroups.com

Here are 2 options, these will change the color of all of the elements in the drop down to the same color.  If you want each of the buttons to be different colors, use a DropDown.

 

Option 1: Redefine the attributes of the Button class to be the color you want.  The downside of this approach is that it will change the color of all of the buttons in your application.  If you do want to change the color of all of your buttons, this is the way to go.

 

<Button>
    -background_color: [1, 0, 0, 1]
    -background_normal: ''

BoxLayout:
    orientation: 'vertical'
    Spinner:
        size_hint_y: .1
        text_autoupdate: True
        values: [str(x) for x in range(8)]
    Label:
        text: 'Blank'
        size_hint_y: .9

 

 

Alternatively you can create a new Option class for the elements that drop down from the spinner, and change the color of the spinner. In the option below, I created a class BlueButton.

 

<BlueButton@Button>
    background_color: [0, 0, 1, 1]
    background_normal: ''    # You can put the name of a file to use as a button image...
    size_hint_y: None
    size_y: '48dp'

BoxLayout:
    orientation: 'vertical'
    Spinner:
        size_hint_y: .1
        background_color: [0, 0, 1, 1]
        background_normal: ''
        text_autoupdate: True
        values: [str(x) for x in range(8)]
        option_cls: 'BlueButton'
       
    Label:
        text: 'Blank'
        size_hint_y: .9
   

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/d8fdd102-94b0-4991-8060-f021d3a6aee5%40googlegroups.com.

 

Ayhan Celik

unread,
Nov 16, 2019, 2:50:29 AM11/16/19
to Kivy users support
Very useful and many thanks.

15 Kasım 2019 Cuma 22:45:35 UTC+3 tarihinde Elliot Garbus yazdı:

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages