In this video I’ll show you how to use the Spinner for Dropdowns with Kivy and Python!
Kivy has a couple of options when it comes to creating dropdowns, but the spinner is probably the easiest one. A Spinner Widget allows you to select from a list of items.
Once you select from the list, we can do whatever we want with the selection. In this video we’ll simply print out the selection to a label above the spinner.
Python Code: spin.py
GitHub Code: spin.py
from kivy.app import App from kivy.uix.widget import Widget from kivy.properties import ObjectProperty from kivy.lang import Builder # Designate Our .kv design file Builder.load_file('spin.kv') class MyLayout(Widget): def spinner_clicked(self, value): self.ids.click_label.text = f'You Selected: {value}' class AwesomeApp(App): def build(self): return MyLayout() if __name__ == '__main__': AwesomeApp().run()
Kivy Design Code: spin.kv
GitHub Code: spin.kv
<MyLayout> BoxLayout: orientation: "vertical" size: root.width, root.height Label: id: click_label text: "Pick Favorite Pizza Below" font_size: 32 Spinner: id: spinner_id text: "Favorite Pizza" values: ["Pepperoni", "Cheese", "Mushroom"] on_text: root.spinner_clicked(spinner_id.text) Label: text: ''
Add comment