Kivy: переключение между экранами из Popup - PullRequest
0 голосов
/ 24 марта 2019

У меня проблемы с переключением экранов в киве. На главном экране есть кнопка, которая открывает всплывающее окно. Внутри всплывающего окна есть кнопка, при нажатии которой отображается экран дисплея.

Вот мой код Python.

#this is MainScreen class
class MainScreen(Screen):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    def displayConfirmationDialog(self):
        confirmationDialog = self.MainScreenConfirmationDialog()
        confirmationDialog.setMessage()
        confirmationDialog.open()

     #this is the function of the button
    def update(self):
          self.displayConfirmationDialog()

    #this is the popup class
    class MainScreenConfirmationDialog(Popup):


        def setYesButton(self):

            screenManager.add_widget(DisplayScreen())
            self.manager.current = 'display_screen'

#this is the DisplayScreen class
class DisplayScreen(Screen):
    pass

Вот мой код киви

<MainScreen>:
    Button:
        text: 'UPDATE'
        on_press:root.update()

<MainScreenConfirmationDialog>:
    GridLayout:
        rows: 3
        Label:
            id: lbl_confirmation
        Button:
            id: b
            text: 'YES'
            on_press: root.setYesButton()
<DisplayScreen>:
    name: 'display_screen'
    GridLayout:
        rows: 4
        row_force_default: True
        row_default_height: 40
        Label:
            text: 'HELLO'
            id: lbl_display_name

Когда я запускаю это, он показывает мне ошибку

    File 'main.py', line 89, in setYesButton self.manager.current = 'display_screen'
AttributeError: 'MainScreenConfirmationDialog' object has no attribute 'manager'

1 Ответ

0 голосов
/ 24 марта 2019

У всплывающего виджета нет доступа к диспетчеру экрана.

Решение

Поскольку у вас есть доступ к глобальной переменной, screenManager, замените self.manager.current = 'display_screen' на screenManager.current = 'display_screen'

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