Created
June 18, 2016 22:26
-
-
Save Alan-FGR/f66ac4b9f4171f21d15b13a5e580ece1 to your computer and use it in GitHub Desktop.
Example of a new dynamic unit in kivy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.app import App | |
from kivy.app import Builder | |
from kivy.uix.stacklayout import StackLayout | |
from kivy.uix.button import Button | |
from kivy.properties import NumericProperty | |
Builder.load_string(""" | |
<Button>: | |
size_hint: None, None | |
size: app.my_unit, app.my_unit*0.4 | |
font_size: app.my_unit*0.2 | |
""") | |
class Test(App): | |
my_unit = NumericProperty(100) | |
def build(self): | |
root_layout = StackLayout() | |
resize_button = Button(text = "increase") | |
resize_button.bind(on_press = self.increase_size) | |
root_layout.add_widget(resize_button) | |
for i in xrange(30): | |
root_layout.add_widget(Button(text = "button "+str(i))) | |
return root_layout | |
def increase_size(self, *args): | |
self.my_unit += 5 | |
print self.my_unit | |
Test().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment