AttributeError: у объекта «SecondWindow» нет атрибута «осел» - PullRequest
1 голос
/ 27 февраля 2020

main.py

def donkey():
    f = open("uni.txt", "a")
    f.write(college)
    f.close()


class MyMainApp(App):
    def build(self):
        return kv


if __name__ == "__main__":
    MyMainApp().run()

my.kv

<SecondWindow>:
name: "second"
GridLayout:
    cols:1
    size: root.width, root.height
    background_color: 1,.5,.3,1
    FloatLayout:
        Button:
            pos_hint: {"x":.2, "top":.15}
            size_hint: .6, .05
            text: "Go Back"
            background_color: .1,.1,.1,1
            on_release:
                app.root.current = "main"
                root.manager.transition.direction = "right"

        Button:
            pos_hint: {"x":.2, "top":.23}
            size_hint: .6, .05
            text: "Continue"
            background_color: .1,.1,.1,1
            on_release: root.donkey()

        Label:
            pos_hint: {"center_x":0.5, "center_y":.85}
            bold: True
            font: 24
            text: "Enter the name of the college"

        TextInput:
            id: college
            pos_hint: {"x":.15, "top":.82}
            size_hint: .7, .045
            multiline: False

Я получаю сообщение об ошибке: AttributeError: У объекта 'SecondWindow' нет атрибута 'donkey'

Осел - это просто функция записи в файл, если кто-то может помочь мне исправить эту ошибку или лучший способ чтения / записи в файл

1 Ответ

1 голос
/ 27 февраля 2020

В вашем файле kv добавьте:

#:import donkey main.donkey

и измените:

on_release: root.donkey()

на:

on_release: donkey()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...