Hey guys, I'm trying to learn Kivy by myself and I'm a self-taught Python student, Sorry if my question is stupid.
import kivy
from kivy.uix.label import Label
from kivy.uix.screenmanager import ScreenManager,Screen
from kivy.lang import Builder
from kivy.uix.button import Button
from kivy.properties import StringProperty
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
Builder.load_string("""
<Input>:
BoxLayout :
orientation : 'vertical'
TextInput:
id : weight
multiline : False
text : 'Weight in kg'
TextInput:
id : height
multiline : False
text : 'Height in centimeters'
Button :
text: 'Calculate the result '
on_press: root.calculate()
Label :
id : result
text : ''
""")
class DataInput(Screen):
result = StringProperty('')
def calculate(self, *args):
result = str(float(self.ids.weight.text) / (float(self.ids.height.text)/100) * (float(self.ids.height.text)/100))
self.ids.result.text = result
class BMIApp(App) :
def build(self):
return DataInput()
if __name__ == '__main__':
BMIApp().run()
The function doesn't calculate at all , it just returns the value of the first TextInput as a float.