android - How to integrate a python program into a kivy app -
i'm working on app written in python kivy modules develop cross-platform app. within app have form takes numerical values. these numerical values passed python program i've written, used calculate other values, , passed app , returned user. outside program not recognizing values i'm trying pass exist. below sample code 3 files i'm using, 2 app , 1 outside program. apologize abundance of seemingly unused kivy modules being imported, use them in full app.
main.py
import kivy import flowcalc kivy.app import app kivy.lang import builder kivy.uix.screenmanager import screenmanager, screen kivy.uix.dropdown import dropdown kivy.uix.spinner import spinner kivy.uix.button import button kivy.base import runtouchapp kivy.uix.textinput import textinput kivy.properties import numericproperty, referencelistproperty, objectproperty, listproperty kivy.uix.gridlayout import gridlayout kivy.uix.scrollview import scrollview kivy.core.window import window kivy.uix.slider import slider kivy.uix.scatter import scatter kivy.uix.image import asyncimage kivy.uix.carousel import carousel builder.load_file('main.kv') #declare screens class formscreen(screen): pass class resultsscreen(screen): pass #create screen manager sm = screenmanager() sm.add_widget(formscreen(name = 'form')) sm.add_widget(resultsscreen(name = 'results')) class testapp(app): def build(self): return sm if __name__ == '__main__': testapp().run()
main.kv
<formscreen>: boxlayout: orientation: 'vertical' asyncimage: source: 'sample.png' size_hint: 1, none height: 50 gridlayout: cols: 2 label: text: 'company industry' label: text: 'sample' label: text: 'company name' textinput: id: companyname label: text: 'company location' textinput: id: companylocation label: text: 'data1' textinput: id: data1 label: text: 'data2' textinput: id: data2 label: text: 'data3' textinput: id: data3 button: text: 'submit' size_hint: 1, .1 on_press: root.manager.current = 'results' <resultsscreen>: boxlayout: orientation: 'vertical' asyncimage: source: 'sample.png' size_hint: 1, none height: 50 label: text: 'results' size_hint: 1, .1 gridlayout: cols: 2 label: text: 'results 1' label: text: results1 label: text: 'results 2' label: text: results2 label: text: 'results 3' label: text: results3 label: text: 'results 4' label: text: results4
otherprogram.py
data1float = float(data1.text) data2float = float(data2.text) data3float = float(data3.text) results1 = data1float + data2float results2 = data1float - data3float results3 = data2float * data3float results4 = 10 * data2float
as far understood want labels in gridlayout in last section of code texts python code. this:
from otherprogram import results1, results2, results3, results4 class resultsscreen(screen): label1_text = results1 label2_text = results2 label3_text = results3 label4_text = results4
then in .kv file access these values calling root widgets attribute.
label: text: root.label1_text
and on.
Comments
Post a Comment