Kivy: Bind Multiple Functions to a Single Button

Today I learned that you can have one button execute multiple functions. Here is how:

.kv file: just list the functions one after another. No commas needed. root.add_info() refers to the add_info() function that I created in my .py file. In this case, the button executes add_info() then changes to the home screen by sliding to the right.

Button:
text: "Add"
on_press:
root.add_info()
root.manager.transition.direction = "right"
root.manager.current = "home_screen"
size_hint: 0.6, 0.6

.py file: I used .bind() twice on the same button.

update_info = Button(text="Yes", size_hint=(0.1, 0.1))

update_info.bind(on_press=lambda x: self.add_update(name))
update_info.bind(on_press=new_popup.dismiss)

This is an example from my code where I updated the name information in a database and then dismissed the popup. I used “lambda x:” to ensure that the self.add_update(name) function would not execute until the button is pressed. If you want to learn more about lambdas, click here: https://www.w3schools.com/python/python_lambda.asp

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Python for and while loops in detailed

Set Your Unity’s Layout to the Industry Standard

Complete Introduction to Java Servlets

How To Create Your Own GitHub Account

TryHackme : Bounty Hacker Walkthrough

CRODO BEST IDO PLATFORM?

Spotlight on Karpenter, Goldilocks and Cluster Autoscaling with Open Source

Deep Understanding of the Docker networking.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rachela

Rachela

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

More from Medium

How to build a Custom Bingo Board with Python

Solving “Letter Boxed” in Python

Namespaces and Scope in Python

Python — Advent of Code: Day 1