@fsdaer

Как получить textinput из другого screen в kivymd?

Как я могу получить и отобразить значение поля mdtextfield с id:debit?
На данный момент выдает такую ошибку:
File "F:\Fin_app\main.py", line 15, in deb
     x = self.manager.get_screen("Debit")
 AttributeError: 'MainApp' object has no attribute 'manager'

Process finished with exit code 1

main.py
from kivymd.app import MDApp
from kivy.lang import Builder
from kivymd.uix.screen import MDScreen

class Debit(MDScreen):
    pass
class MainApp(MDApp):

    def build(self):
        return Builder.load_file("MainApp.kv")
    def change_title(self, title):
        self.root.ids.backdrop.title = title

    def deb(self, *args):
        x = self.manager.get_screen("Debit")
        y = x.ids.debit.text
        print(y)# here I need to output the value of the debit field

    def cal1(self):
        print("saving works")


MainApp().run()


Mainapp.kv

MDScreen:
    MDBackdrop:
        id: backdrop

        header_text: "Меню"

        title: "Fin Save"

        radius_left: 30
        radius_right: 30

        right_action_items: [['content-save', lambda x: app.cal1()]]
        left_action_items: [['arrow-down', lambda x: app.backdro_open()]]

        MDBackdropBackLayer:
            id: backlayer

            ScreenManager:
                id: manager

                Debit:
                    name: 'Debit'

        MDBackdropFrontLayer:

            ScrollView
                do_scroll_y: False
                MDList:
                    OneLineAvatarListItem:
                        text: "Top up your deposit"
                        on_release:
                            backdrop.open()
                            app.change_title(self.text)
                            manager.current = 'Debit'
                        IconLeftWidget:
                            icon: "bank-transfer-in"

                    OneLineAvatarListItem:
                        text: "Просмотреть мои цели"
                        on_release:
                            backdrop.open()
                            app.change_title(self.text)
                        IconLeftWidget:
                            icon: "binoculars"

<Debit@MDScreen>
    name: "Debit"
    debit: debit
    btn1: btn1
    md_bg_color: app.theme_cls.primary_dark
    MDGridLayout:
        cols: 2
        MDTextField:
            id: debit
            hint_text: "Input value"
            mode: "rectangle"
            color_mode: 'accent'
        OneLineAvatarListItem:
            id: btn1
            text: "deposit"
            on_press:
                app.deb(self)


<Targets@MDScreen>
    md_bg_color: app.theme_cls.primary_dark
    MDLabel:
        text: "My goals"
        halign: 'center'
  • Вопрос задан
  • 90 просмотров
Решения вопроса 1
Lord_of_Rings
@Lord_of_Rings
Python developer
x = self.root.ids.manager.get_screen("Debit")
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы