constructor and kv files

60 views
Skip to first unread message

jdd...@gmail.com

unread,
Apr 18, 2015, 4:21:33 PM4/18/15
to kivy-...@googlegroups.com
Hi, I have a question concerning the constructors of self-defined widgets. 

If we defined the widget in a kv file, can we still define a constructor __init__() ? 

Because apart from defining the layout etc in kv file, I want to call some functions after initialisation. 

Now what I do to achieve this, is that in the App class' build() method I build the widget and then call it's function, but this might not be a good practice...

Alexander Taylor

unread,
Apr 18, 2015, 5:48:31 PM4/18/15
to kivy-...@googlegroups.com
Certainly, you can create any widget subclass in python as normal and put whatever you like in its __init__. Any kv rule for the widget will be applied when you call super(YourWidgetName, self).__init__(*args, **kwargs).

Just make sure your kv for the widget is a normal kv rule ('<YourWidgetName>:'), not a dynamic class (which would be e.g. '<YourWidgetName@WidgetBaseClass>').

mx

unread,
Apr 19, 2015, 3:38:44 AM4/19/15
to kivy-...@googlegroups.com
Thank you Alexander, that works ! 

--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/Ad60wyE199k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages