将文本从文本框传递到返回数组的函数

时间:2019-02-04 09:19:11

标签: python textbox kivy

我必须使用kivy在python中编写一个程序,该程序将文本输入文本框,然后将其传递给进行网页抓取的功能,然后执行很多操作,然后返回字符串数组,而数组中的最后一个元素是对数组,因此我真的很困惑并且发送了很多时间。所以我必须写两个kv文件还是一个文件?这是我简单的kivy代码作为开始。

我尝试了,但是没有用

#textInput.py
from app import *
Builder.load_file('textInput.kv')

require('1.10.0')


class MainScreen(BoxLayout):
    def __init__(self):
        self.super(MainScreen, self).__init__()
    def btn_click(self):
        name =self.BoxLayout.BoxLayout.TextInput
       #the function that takes the output of the text field 
        get_company_name(name)
        #
        #
        #
        # here I will call the function that returns the array so how to     pass the answer 
        # and also pass to where ? shall I use the same kv file or create     another one 
class Test(App):
    def build(self):
        self.title = 'CompanyInfoApp'
        return MainScreen()

if __name__ == '__main__':
    Test().run()

    lbl:My_label     方向:“垂直”

# Third section title
Label:
    size_hint: (1, .1)
    text: 'Welcome To compnay info App'
    font_size: 25

# Third section Box
BoxLayout:
    Button:
           text:"let's start"
           on_press:root.btn_click()

    size_hint: (1, .2)
    padding: [180, 180, 180, 180]
    BoxLayout:
        Label:

            pos_hint:{'x': .3, 'y': .6}
            text: 'Enter the Company Name:'
            text_size: self.width-20, self.height-20
        TextInput:
            height: self.minimum_height
            pos_hint:{'x': .3, 'y': .6}
            multiline: False
            text: ''

1 个答案:

答案 0 :(得分:0)

尝试给您的TextInput小部件一个id。然后,您可以使用TextInput小部件来访问id小部件的文本数据。

这是一个基本示例:

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import *

main_kv = """
<Main>:
    orientation: 'vertical'
    TextInput:
        # TextInput's id
        id: txtinput
        text: ''
    Button:
        text: "print text"
        on_press: root.btn_click()
"""

class Main(BoxLayout):
    def btn_click(self):
        name = self.ids['txtinput'].text
        print(name)

class Test(App):
    def build(self):
        Builder.load_string(main_kv)
        return Main()

Test().run()