5

The init method cannot be used for this, because the kv file is processed after the object has been constructed. The build() method could be used in the App class, but I need this in a Widget (e.g. non-app) class.

nagylzs
  • 3,954
  • 6
  • 39
  • 70
  • 2
    Not sure if this will help, but the Application class has an `on_start()` method that is run just before starting the application main loop. Perhaps you can use that to execute your method. – John Anderson Nov 11 '17 at 18:30
  • See also [this related answer overriding `App.on_start()` to run arbitrary logic after app startup](https://stackoverflow.com/a/42142596/2809027) – just as suggested by @JohnAnderson above. – Cecil Curry Jun 09 '22 at 03:09
  • There is an `on_kv_post()` method that is called after all the `kv` rules have been applied for that widget. See the [documentation](https://kivy.org/doc/stable-2.0.0/api-kivy.uix.widget.html#kivy.uix.widget.Widget). – John Anderson Jun 09 '22 at 16:03

1 Answers1

1

We have the clock object for that, you can schedule the execution of that method once or repeatedly after a the time that you want and his usage is very simple

Simon Mengong
  • 2,625
  • 10
  • 22
  • You mean something like calling "Clock.schedule_once(self.after_created, 0)" from __init__? Yes, I could have figured that out by myself, but I was hoping that there is a concrete method that will be called in the base Widget class, and so it makes inheritance and polymophism possible. Well, if that I what I have to do then I'll do it. :-) – nagylzs Nov 11 '17 at 11:06
  • Yes, but indeed kivy has no concept of a "loaded" state, initial settings of rules are no different from the subsequent ones, and initialisation might even take a few frames if some dispatching use triggers or clock event themselves. – Tshirtman Nov 12 '17 at 01:10