Skip to content
Snippets Groups Projects
Commit 33a1ef09 authored by Brady James Garvin's avatar Brady James Garvin
Browse files

Revised code to avoid student confusion from last semester.

parent 8bf8e85b
No related branches found
No related tags found
No related merge requests found
...@@ -17,10 +17,10 @@ BoxLayout: ...@@ -17,10 +17,10 @@ BoxLayout:
on_press: app.print_total() on_press: app.print_total()
<Field>: <Field>:
BoxLayout: orientation: 'horizontal' # Field is a kind of BoxLayout
orientation: 'horizontal' Label:
Label: text: root.label_text # Refers to a property declared in the Field class
text: root.label_text TextInput:
TextInput: id: input
id: input multiline: False
multiline: False write_tab: False
...@@ -4,10 +4,7 @@ from kivy.properties import StringProperty ...@@ -4,10 +4,7 @@ from kivy.properties import StringProperty
class Field(BoxLayout): class Field(BoxLayout):
label_text = StringProperty('Data: ') label_text = StringProperty()
def __init__(self, **kwargs):
super().__init__(**kwargs)
class DemoApp(App): class DemoApp(App):
...@@ -26,7 +23,7 @@ class DemoApp(App): ...@@ -26,7 +23,7 @@ class DemoApp(App):
total = 0 total = 0
for field in container.children: for field in container.children:
try: try:
total += int(field.ids.input.text) total += float(field.ids.input.text) # refer to a subwidget by id
except ValueError: except ValueError:
pass # ignore non-numeric values pass # ignore non-numeric values
print('Total of fields\' numeric values: {total}'.format(total=total)) print('Total of fields\' numeric values: {total}'.format(total=total))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment