python - Calculation in Kivy with inputs from several widgets (and output to a different one) -


i'm trying build app kivy asks numbers , returns calculation, need input numbers provided on different widgets. i've been searching way that, , seems can done objectproperty() or numericproperty(), can't figure correct way. barebone example (not working, obviously), below code app 2 numbers introduced , calculates sum. main.py is

    kivy.app import app     kivy.uix.boxlayout import boxlayout      class sumroot(boxlayout):         pass      class firstinput(boxlayout):         pass      class secondinput(boxlayout):         pass      class outputslide(boxlayout):         def sum_of_inputs(self):             self.resultado.text = str(float(self.first_input.text)+float(self.second_input.text))      class sumapp(app):         pass      if __name__ == '__main__':         sumapp().run() 

and sum.kv files is

    sumroot:      <sumroot>:         carousel: carousel         first_slide: first_slide         second_slide: second_slide         third_slide: third_slide          carousel:             id: carousel             firstinput:                 id: first_slide             secondinput:                 id: second_slide             outputslide:                 id: third_slide      <firstinput>:         orientation: "vertical"         first: first_input         textinput:             id: first_input         button:             text: "next"             on_release: app.root.carousel.load_slide(app.root.second_slide)      <secondinput>:         orientation: "vertical"         second: second_input         textinput:             id: second_input         button:             text: "sum"             on_press: root.sum_of_inputs()             on_release: app.root.carousel.load_slide(app.root.third_slide)      <outputslide>:         orientation: "vertical"         result: result_output         label:             id: result_output 

the intended behavior when 1 presses "sum" button calculates sum, goes next slide , displays sum. suggestions welcomed.

1) pass references of inputs outputslide, calculations:

outputslide:     id: third_slide     first_input: first_slide.first     second_input: second_slide.second 

2) add object properties in py file, hold them:

from kivy.properties import objectproperty ... class outputslide(boxlayout):      first_input = objectproperty()     second_input = objectproperty()     result = objectproperty()  # 1 aswell, don't leave bare ids 

3) calculate result on_press correctly:

<secondinput>: .... on_press: app.root.third_slide.sum_of_inputs() 

additionally, fix naming bugs in outputscreen.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -