Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何将python程序集成到kivy应用程序中_Android_Python_Kivy_Kivy Language - Fatal编程技术网

Android 如何将python程序集成到kivy应用程序中

Android 如何将python程序集成到kivy应用程序中,android,python,kivy,kivy-language,Android,Python,Kivy,Kivy Language,我正在开发一个用python编写的带有kivy模块的应用程序,以开发一个跨平台的应用程序。在这个应用程序中,我有一个表格,其中包含一些数值。我希望将这些数值传递给我编写的另一个python程序,用于计算其他一些值,然后传递回应用程序并返回给用户。外部程序目前没有意识到我试图传递给它的值的存在。下面是我正在使用的3个文件的示例代码,2个用于应用程序,1个用于外部程序。我为大量似乎未使用的kivy模块被导入而道歉,我在整个应用程序中都使用了它们 main.py import kivy import

我正在开发一个用python编写的带有kivy模块的应用程序,以开发一个跨平台的应用程序。在这个应用程序中,我有一个表格,其中包含一些数值。我希望将这些数值传递给我编写的另一个python程序,用于计算其他一些值,然后传递回应用程序并返回给用户。外部程序目前没有意识到我试图传递给它的值的存在。下面是我正在使用的3个文件的示例代码,2个用于应用程序,1个用于外部程序。我为大量似乎未使用的kivy模块被导入而道歉,我在整个应用程序中都使用了它们

main.py

import kivy
import flowcalc

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.dropdown import DropDown
from kivy.uix.spinner import Spinner
from kivy.uix.button import Button
from kivy.base import runTouchApp
from kivy.uix.textinput import TextInput
from kivy.properties import NumericProperty, ReferenceListProperty, ObjectProperty, ListProperty
from kivy.uix.gridlayout import GridLayout
from kivy.uix.scrollview import ScrollView
from kivy.core.window import Window
from kivy.uix.slider import Slider
from kivy.uix.scatter import Scatter
from kivy.uix.image import AsyncImage
from kivy.uix.carousel import Carousel

Builder.load_file('main.kv')

#Declare Screens

class FormScreen(Screen):
    pass

class ResultsScreen(Screen):
    pass

#Create the 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()
主电压(千伏)

<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

据我所知,您希望代码最后一部分的GridLayout中的标签从python代码中获取文本。你可以这样做:

from otherprogram import results1, results2, results3, results4

class ResultsScreen(Screen):

    label1_text = results1
    label2_text = results2
    label3_text = results3
    label4_text = results4
然后在.kv文件中,您可以通过调用这些值的根窗口小部件属性来访问这些值

    Label:
        text: root.label1_text

诸如此类。

不幸的是,这不起作用,我得到一个错误:ImportError:cannotimportname results1这只是一个示例代码。我是说试着做这样的事。尝试将变量从otherprgram导入kivy main.py文件。我明白,我也在使用示例。我是说将变量导入main.py不起作用。引发此异常的原因是什么?与上述代码唯一不同的是,我在main.py中添加了“来自其他程序导入结果1、结果2、结果3、结果4”和“来自主导入数据1、数据2、数据3”,我无法以这种方式真正帮助您。你可以把你的整个项目发电子邮件给我,这样我就可以帮助你了。aminetesamian1371@gmail.com
    Label:
        text: root.label1_text