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.
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))
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