我的文本输入有问题。我无法访问其内容

问题描述 投票:0回答:0

我想检索文本,将文本输入输入到 python 文件中的变量中。我尝试了很多在网上看到的解决方案,但没有一个有效。我真的需要尽快帮助。预先感谢您提供任何潜在的帮助

在Python文件中:

# from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty
from kivy.properties import ObjectProperty
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput

class MainWidget(Widget):  
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    def get_text():    
        text = self.root.text_id.text 
        print(text)

    def test(self):
        print("it work")
    
class Counter_app(BoxLayout):
    count_var = 0
    text = StringProperty("0")

    def count_click(self):
        self.count_var += 1 
        self.text = str(self.count_var)

class  appliApp(App):
    def  build(self):
        return MainWidget()

appliApp().run()

//在 Kv 文件中

主要小部件:

<Counter_app>:
    Button:
        background_color: "blue"
        text: "count"
        on_press: root.count_click()
               
    Label:
        text: root.text
        color: "green"
        font_size: "50"
        canvas.before:
            Rectangle:
                pos: self.pos
                size: self.size
                source: 'images/img2.jpg'

<font@BoxLayout>: 
    Image:
        source: "images/img2.jpg"
        size: 500,500
    Label:
        background_image: "images/img6"
        background_color: "green"
       
<MainWidget>:
    canvas.before:
        Rectangle:
            pos: self.pos
            size: self.size
            source: 'img3.png'

    Button:
        pos: 300, 100 
        text: "get text"
        on_press: root.get_text()

    TextInput:
        id: 'text_id'
        hint_text: "Enter your name"

我想检索将 textInput 输入到 python 文件中的变量中的文本。我尝试了很多在网上看到的解决方案,但没有一个有效。我真的需要尽快帮助。预先感谢您提供任何潜在的帮助

python variables get kivy textinput
© www.soinside.com 2019 - 2024. All rights reserved.