Select Git revision
example2.py
Forked from
SOFT Core / SOFT 161 and 162 / Testability Examples
1 commit behind, 1 commit ahead of the upstream repository.
Brady James Garvin authored
example2.py 1.16 KiB
from math import inf
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import NumericProperty, StringProperty
class Field(BoxLayout):
label_text = StringProperty()
class Example2App(App):
smallest_positive = NumericProperty(inf)
def add_field(self):
container = self.root.ids.fields
container.add_widget(Field(label_text=f'Field #{len(container.children)}: '))
def remove_field(self):
container = self.root.ids.fields
if len(container.children) > 0:
container.remove_widget(container.children[0])
@staticmethod
def _find_smallest_positive(values):
result = inf
for value in values:
if 0 < value < result:
result = value
return result
def update(self):
container = self.root.ids.fields
values = []
for field in container.children:
try:
values.append(float(field.ids.input.text))
except ValueError:
pass
self.smallest_positive = self._find_smallest_positive(values)
if __name__ == '__main__':
app = Example2App()
app.run()