diff --git a/main.py b/main.py index 4990bdcf72c981287474e215e9a4af1cff98c2cc..adcd1c8f1c31510020bea3ece98ddd2d7e971986 100644 --- a/main.py +++ b/main.py @@ -13,6 +13,9 @@ class Classification(Enum): class TriangleApp(App): + a = StringProperty('') + b = StringProperty('') + c = StringProperty('') classification = StringProperty() @staticmethod @@ -36,15 +39,23 @@ class TriangleApp(App): return Classification.SCALENE def update(self): - ids = self.root.ids try: - self.classification = TriangleApp.classify(int(ids.a.text), int(ids.b.text), int(ids.c.text)).value + self.classification = TriangleApp.classify(int(self.a), int(self.b), int(self.c)).value except ValueError: self.classification = f'{Classification.INVALID.value} (non-integer sides)' def on_start(self): self.update() + def on_a(self, _, __): + self.update() + + def on_b(self, _, __): + self.update() + + def on_c(self, _, __): + self.update() + if __name__ == '__main__': app = TriangleApp() diff --git a/triangle.kv b/triangle.kv index f9de87bf530a17a6fc16d98c50576d899624499c..8468ab80a8f0e9cf249127fee465090af61f2805 100644 --- a/triangle.kv +++ b/triangle.kv @@ -13,12 +13,11 @@ BoxLayout: Widget: size_hint: (0.25, 1.0) TextInput: - id: a multiline: False write_tab: False - text: '' + text: app.a font_size: sp(24) - on_text: app.update() + on_text: app.a = self.text Widget: BoxLayout: orientation: 'horizontal' @@ -31,12 +30,11 @@ BoxLayout: Widget: size_hint: (0.25, 1.0) TextInput: - id: b multiline: False write_tab: False - text: '' + text: app.b font_size: sp(24) - on_text: app.update() + on_text: app.b = self.text Widget: BoxLayout: orientation: 'horizontal' @@ -49,12 +47,11 @@ BoxLayout: Widget: size_hint: (0.25, 1.0) TextInput: - id: c multiline: False write_tab: False - text: '' + text: app.c font_size: sp(24) - on_text: app.update() + on_text: app.c = self.text Widget: Widget: BoxLayout: