K
K
Kilowatt2020-06-10 03:47:31
Python
Kilowatt, 2020-06-10 03:47:31

How to get textfield text from kv?

Hello, you need to get from the textfield, which is in kv, its text into the main class

import kivy
from kivy.lang.builder import Builder
from kivymd.app import MDApp
from kivymd.uix.dialog import MDDialog
from kivymd.uix.button import MDFlatButton, MDRaisedButton
from kivymd.uix.textfield import MDTextField
from kivy.uix.boxlayout import BoxLayout
KV="""
<Content>:
    orientation: 'vertical'
    size_hint_y: None
    height: "60dp"
    MDTextField:
        id: textnumber
        hint_text: "логин"
        height:'70dp'
"""
class Content(BoxLayout):
    pass
        
class TestApp(MDApp):
    def build(self):
        Builder.load_string(KV)
        dialog = MDDialog(size_hint_x=.6,title='Авторизация', content_cls=Content(), type='custom',
            buttons=[MDFlatButton(text='Отмена'),
        MDRaisedButton(text='ОК')])
        dialog.open()
TestApp().run()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
BitNeBolt, 2020-06-10
@BitNeBolt

Kilowatt , then try to override (set, etc.) the on_text method. From it you will be able to get the text every time it is updated.
If you need to take a value upon approval, then write the on_text_validate method, this is what will be performed upon confirmation. Since there is no text in the method attributes, in the on_text method change the value of the application variable you created.
https://kivymd.readthedocs.io/en/latest/components...

A
Aarrtteemm, 2020-11-14
@Aarrtteemm

dialog.content_cls.ids.textnumber.text = 'your text'
print(dialog.content_cls.ids.textnumber.text)
But add self to dialog field

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question