Skip to content

Instantly share code, notes, and snippets.

@Alan-FGR
Last active July 7, 2016 14:51
Show Gist options
  • Select an option

  • Save Alan-FGR/706eb76ee887fbdde8d3fa9e8267fb9c to your computer and use it in GitHub Desktop.

Select an option

Save Alan-FGR/706eb76ee887fbdde8d3fa9e8267fb9c to your computer and use it in GitHub Desktop.
If you uncomment the code on line 15, it works properly
from kivy.app import App
from kivy.app import Builder
from kivy.uix.stacklayout import StackLayout
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.properties import NumericProperty
Builder.load_string("""
<MyLabel>:
size_hint: 1, None
font_size: app.some_multiplier*10
<MySubLabel>:
font_size: 10 # or app.some_multiplier
""")
class MyLabel(Label):
pass
class MySubLabel(MyLabel):
pass
class Test(App):
some_multiplier = NumericProperty(1.0)
def build(self):
root_layout = StackLayout()
root_layout.add_widget(MyLabel(text="MYLABEL"))
root_layout.add_widget(MySubLabel(text="MYSUBLABEL"))
property_change_button = Button(text="Change Multiplier", size_hint_y=None)
property_change_button.bind(on_press=self.change_multiplier)
root_layout.add_widget(property_change_button)
return root_layout
def change_multiplier(self, *args):
self.some_multiplier += 0.5
if __name__ == "__main__":
Test().run()
@Alan-FGR
Copy link
Author

Alan-FGR commented Jul 7, 2016

While using 'or' is a cool trick, kivy should always respect the user defined rules no matter what.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment