簡體   English   中英

Kivy:在Popup的屏幕之間切換

[英]Kivy: Switching between screens from Popup

我無法在kivy中切換屏幕。 從MainScreen有一個按鈕,可以打開一個Popup。 在彈出窗口內有一個按鈕,按下該按鈕時,將顯示DisplayScreen。

這是我的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

這是我的kivy代碼

<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'

Popup小部件無權訪問screenmanager。

既然你可以訪問全局變量, screenManager ,更換self.manager.current = 'display_screen'screenManager.current = 'display_screen'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM