is it possible to give background to spinner item kivy

268 views
Skip to first unread message

talha.t...@gmail.com

unread,
Aug 28, 2018, 2:33:43 AM8/28/18
to Kivy users support
I want to give different color for differnt item of the spinner here is my code portion for spinner how can i solve it 
<MySpinnerOption@SpinnerOption>:
color:.501,.756,.172, 1 
background_normal:""
background_color:(.949,.976,.917, 1)
size_hint_y:None
pos_hint:{"center_x":.5,"center_y":.5}
Spinner:
   pos_hint:{"center_x":.5,"center_y":.5}
   background_normal:""
   background_color:(.501,.756,.172, 1)
   id:spinner_3
   size_hint_y:None
   size_hint_x:.4
   height:50
   text:'country'
   values:root.country_name
   on_text:root.updatePhone(spinner_3.text)
   option_cls: Factory.get("MySpinnerOption")

ZenCODE

unread,
Aug 28, 2018, 10:52:54 AM8/28/18
to Kivy users support
You can use your own images and drawings? E.g. below, by changing the png paths of course...

<SpinnerOption>:
canvas.before:
Color:
rgba: [0, 0.3, 0, 0.95] # if root.state == "normal" else [0, 1, 1, 0.95]
RoundedRectangle:
radius: [5] * 4
pos: self.x + 1, self.y + 1
size: self.width - 2, self.height - 2
background_normal: 'graphics/blank.png'
background_down: 'graphics/blank.png'

<Spinner>:
canvas.before:
Color:
rgba: [0.1, 0.75, 0.1, 0.5] if root.state == "normal" else [0.5, 1, 1, 0.5]
RoundedRectangle:
radius: [5] * 4
pos: self.x + 1, self.y + 1
size: self.width - 2, self.height - 2
background_normal: 'graphics/blank.png'
background_down: 'graphics/blank.png'

Talha Training

unread,
Aug 29, 2018, 12:42:54 AM8/29/18
to kivy-...@googlegroups.com
thank you for your reply but how can i change my background_normal's path of SpinnerOption every time


--
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 post to this group, send email to kivy-...@googlegroups.com.
Visit this group at https://groups.google.com/group/kivy-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/884611cb-db76-4ed6-ab8d-303477255cd4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ZenCODE

unread,
Aug 29, 2018, 9:16:50 AM8/29/18
to Kivy users support
If I understand you correctly, you could bind to the 'on_text' event for the SpinnerOption as set the background there? That would allow you to have different background for each item in the dropdown list. Does that answer your question?
Reply all
Reply to author
Forward
0 new messages