Kivy: Trigger Method or Function on Entering a Screen

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"

--

--

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

19 Followers

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