передача текста из текстового поля в функцию, которая возвращает массив - PullRequest
0 голосов
/ 04 февраля 2019

Мне нужно написать программу на python, использующую kivy, которая берет текст в текстовое поле и передает его функции, выполняющей очистку веб-страниц, и во многих случаях возвращает массив строк, а последним элементом в массиве является массив пар, поэтомуЯ действительно запутался и отправил много времени. Поэтому я должен написать два файла kv или только один файл?Вот мой простой код для начала.

Я пытался, но он не работает

#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 голосов
/ 04 февраля 2019

Попробуйте дать вашему 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()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...