Skip to content

Instantly share code, notes, and snippets.

@clayote
Created December 14, 2015 20:15
Show Gist options
  • Select an option

  • Save clayote/a0c9d38016d8cb783e50 to your computer and use it in GitHub Desktop.

Select an option

Save clayote/a0c9d38016d8cb783e50 to your computer and use it in GitHub Desktop.
I want this button to open up that ListView but it won't.
from kivy.app import App
from kivy.adapters.simplelistadapter import SimpleListAdapter
from kivy.lang import Builder
from kivy.properties import ObjectProperty
from kivy.uix.button import Button
from kivy.uix.dropdown import DropDown
class ListDropDown(DropDown):
adapter = ObjectProperty()
class ListDropDownButton(Button):
mainbut = ObjectProperty()
def on_release(self, *args):
self.mainbut.text = self.text
class DropListTestApp(App):
def build(self):
b = Button(
text='Press me',
size_hint_y=None,
pos_hint={'top': 1},
height=100
)
a = SimpleListAdapter(
data=['spam', 'eggs', 'ham'],
cls=ListDropDownButton,
args_converter=lambda i, v: {
'text': v,
'mainbut': b
}
)
ldd = ListDropDown(adapter=a)
b.bind(on_release=ldd.open)
return b
Builder.load_string("""
<ListDropDown>:
ListView:
adapter: root.adapter
""")
if __name__ == '__main__':
DropListTestApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment