python - Tracking down text form kivy dropdown button -


hi guys have question kivy dropdown. have example:

def dropdownbutton(self):     dropdown = dropdown()     classlist = ['barbarian', 'knight', 'sorcerer', 'typical seba', 'hunter']     index in classlist:         btn = button(text='%s' % index, size_hint_y=none, height=44)         btn.bind(on_release=lambda btn: dropdown.select(btn.text))         dropdown.add_widget(btn)     mainbutton = button(text='class', size_hint=(none, none))     mainbutton.bind(on_release=dropdown.open)     dropdown.bind(on_select=lambda instance, x: setattr(mainbutton, 'text',                                                         x))       return mainbutton 

and want do, track current btn.txt choose, mby dumb, spend hour on this... can me? btn.text returns me hunter time

you've hit classic problem defining lambda functions in loop. try:

btn.bind(on_release=lambda btn=btn: dropdown.select(btn.text)) 

Comments

Popular posts from this blog

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -