Reputation: 207
I would like to change a base widget property in kivy. This is easily done in the kivy language like so:
<Label>:
font_size: sp(30)
This does not have to be in my widget tree to affect all classes that use Label as a base class upon app initialization. So, my following example app shows up with two buttons whose text is larger than the default, which is what I want.
testApp.py
class Main_Screen(Screen):
pass
class Root_Widget(ScreenManager):
pass
class testApp(App):
def build(self):
return Root_Widget()
if __name__ == '__main__':
testApp().run()
test.kv
<Root_Widget>:
Main_Screen:
BoxLayout:
Label:
text: 'Label1'
Label:
text: 'Label2'
<Label>:
font_size: sp(30)
However, I would like to update this font_size value based on my window size (which I know how to change dynamically I just haven't included all that here). But how do I access the font_size property of the base class widget from python so that it can be changed?
Questions
How can I accomplish this change via python in a way that allows me to change it at the instantiation of my app?
Upvotes: 2
Views: 461
Reputation: 16031
from kivy.uix.label import Label
from kivy.metrics import sp
Label.font_size = sp(30)
from kivy.uix.label import Label
from kivy.metrics import sp
class testApp(App):
def build(self):
Label.font_size = sp(30)
return Root_Widget()
Upvotes: 3