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: ''

John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of the first dot com boom. After that he developed the award-winning Submission-Spider search engine submission software that's been used by over 3 million individuals, businesses, and governments in over 42 countries. He's written several Amazon #1 best selling books on coding, and runs a popular Youtube coding channel.

View all posts

Add comment

Your email address will not be published. Required fields are marked *

John Elder