How to Create a Drop Down List in Kivy

Rachela
1 min readJul 30, 2021

--

Below I have provided an example for creating a drop down list in Kivy using ScreenManager. Just as a note, this will work in all layouts, but I find that GridLayout to be the easiest to control. You can copy and paste this into your code.

from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder

Builder.load_file("try_out_app.kv")

class ExampleScreen(Screen):
pass

class RootWidget(ScreenManager):
pass

class Demo(App):

def build(self):

return RootWidget()


if __name__ == "__main__":
Demo().run()

try_out_app.kv

<ExampleScreen>:
name: "example_screen"
GridLayout:
cols: 1
padding: 10, 10
size_hint: 0.5, 0.5
Button:
id: btn
text: "Press me !!"
size_hint: None, None
on_parent: drop_content.dismiss()
on_release: drop_content.open(self)
DropDown:
id: drop_content
on_select: btn.text = f'{args[1]}' # see note below
Button:
id: btn1
text: 'First Item'
size_hint: None, None
height: 35
on_release: drop_content.select('First Item')
Button:
id: btn3
text: 'Second Item'
size_hint: None, None
height: 35
on_release: drop_content.select('Third Item')

<RootWidget>:
ExampleScreen

args[1] refers to the second element in elements of the DropDown list, in this case each arg is a Button. Therefore args[1] would be the text for each button under the DropDown list.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Rachela
Rachela

Written by Rachela

I am a librarian and new computer programmer creating an app with Python and Kivy to document the plants in my garden.

Responses (2)

Write a response