I have a kivy program in python which has a textbox and a few buttons. I have written the ui in kivy language and I need to run a function which updates the text box and waits for the user to press a button. Is there an on_load property I can use or some sort of thing to run this function when all the widgets have been loaded. The .kv file:
<MainGui>:
id: layout1
orientation: 'horizontal'
#I would like for some sort of event like below to run my function:
on_load: root.myfunction()
Create an application¶ Creating a kivy application is as simple as: sub-classing the App class. implementing its build() method so it returns a Widget instance (the root of your widget tree) instantiating this class, and calling its run() method.
Kivy apps have a default build() method, which you can see here; it just returns an empty widget. Generally kivy has two methods to create the root widget tree, either through overriding build() or by defining a root widget in a kv file. For more information see the documentation on creating an application.
Loading KV Files There are two methods to load a KV file to a Kivy applicatoin. By Name Matching During application start, Kivy looks for a KV file that matches the application class name.
Kivy is a free and open source Python framework for developing mobile apps and other multitouch application software with a natural user interface (NUI). It is distributed under the terms of the MIT License, and can run on Android, iOS, Linux, macOS, and Windows.
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
class DemoApp(App):
def build(self):
self.layout = layout = BoxLayout()
layout.label = Label(text="INITIAL TEXT")
layout.add_widget(layout.label)
return(self.layout)
def on_start(self, **kwargs):
self.layout.label.text = "APP LOADED"
DemoApp().run()
I'm not sure what exactly you mean by 'loaded' (that is, what aspect of the widget creation is important to your function), but perhaps you could use on_parent
which occurs when the widget is added to another widget.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With