Reputation: 59
I'm looking for a way to change the color/ background and size of the options/ buttons that are shown within my spinner widget in kivy. I've read that the dropdown_buttons are defined in the option_cls. My spinners are defined in the .kv file and look like this:
Spinner:
id: select_letter
text: "Choose a letter"
values: ('A', 'B', 'C')
background_normal: 'graphics/buttons/dropdown_green.png'
background_down: 'graphics/buttons/dropdown_blue.png'
on_text:
root.set_values()
How can I change the properties of the spinner options while keeping my spinner defined in kivy? Is there a way to directly change the size and background of it in the kv? Thanks!
Upvotes: 1
Views: 2123
Reputation: 131
I was also looking for a way to change the color/ background and size of the options/ buttons that are shown within my spinner widget in kivy.
The below code snippet worked for me
#:import Factory kivy.factory.Factory
<MySpinnerOption@SpinnerOption>:
background_color: [0, 0, 1, 1] # blue colour
background_down: ''
<MyThing>:
Spinner:
id: select_letter
text: "Choose a letter"
values: ('A', 'B', 'C')
background_normal: 'graphics/buttons/dropdown_green.png'
background_down: 'graphics/buttons/dropdown_blue.png'
option_cls: Factory.get("MySpinnerOption")
on_text:
root.set_values()
Reference: https://github.com/kivy/kivy/wiki/Styling-a-Spinner-and-SpinnerOption-in-KV
Upvotes: 1
Reputation: 2231
Since there you provide no actual code, I can't test it, but you can try to change the option_cls
of the Spinner
you use, with one that you modified.
Spinner:
id: select_letter
text: "Choose a letter"
values: ('A', 'B', 'C')
background_normal: 'graphics/buttons/dropdown_green.png'
background_down: 'graphics/buttons/dropdown_blue.png'
option_cls: MySpinnerOption
on_text:
root.set_values()
<MySpinnerOption@SpinnerOption>:
background_color: [0, 0, 1, 1] # blue colour
Upvotes: 0