【发布时间】:2019-03-24 21:52:25
【问题描述】:
我在 kivy 中切换屏幕时遇到问题。 从 MainScreen 有一个按钮可以打开一个弹出窗口。 在弹出窗口中有一个按钮,按下时会显示 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'
【问题讨论】: