Differences between form_show and init methods

__init__() is called once, to give the object (in this case, an instance of your Form) its internal (instance) variables.

Some of that work is done during the execution of self.init_components(**properties). Until that function call completes, the Form, as it would appear in the IDE, is not completely built. Some instance variables may be missing, their values may be missing, or they might not be connected to their corresponding visual components.

The call to form_show() occurs after __init__() has completed. So, by that time, the work done by self.init_components(**properties) has also completed. It looks like your code, currently in form_show(), depends on that completion.

form_show() is called whenever the Form is to be drawn on the screen. This may be the first “showing”, or, if you’ve subsequently hidden this Form, when it is unhidden, or when the form’s self.visible is set. So, depending on the circumstances, form_show() may be called more than once.

If you need to make sure that your code is called exactly once, then you may want to call it within __init__(), after the self.init_components(**properties).

4 Likes