Kivy: Trigger Method or Function on Entering a Screen

Rachela
1 min readJul 25, 2021

Use on_enter: in your .kv file

<ShowGardenScreen>:
on_enter: root.populate_info()

In this case, my root.populate_info() refers to a method in the ShowGardenScreen class within my .py file. It searches a database and then feeds all the information about that specific function to the Labels and Buttons within that screen. Here is the above in context:

<ShowGardenScreen>:
name: "show_garden_screen"
on_enter: root.populate_info()
GridLayout:
cols: 1
padding: 10, 10
Label:
id: current_garden_name
text: "Garden Name"
font_size: "30sp"
size_hint: 0.25, 0.25
Label:
text: "Notes:"
font_size: "25sp"
size_hint: 0.1, 0.1
Label:
id: notes_for_this_garden
text: "garden notes"
font_size: "20sp"
size_hint: 0.2, 0.2
RecycleView:
id: plants_list
data: []
viewclass: "RecycleButton"
RecycleBoxLayout:
default_size: None, dp(60)
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
GridLayout:
cols: 2
padding: 10, 10
size_hint: 0.25, 0.25
Button:
text: "Home"
on_press:
root.manager.transition.direction = "right"
root.manager.current = "home_screen"
Button:
text: "Search Plants"
on_press:
root.manager.current = "search_plants_screen"

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.

No responses yet

Write a response