我正在使用npyscreen构建一个简单的应用程序来构建精美的菜单。正如文档所说,我使用self.parentApp
检索的switchForm()
方法来更改当前显示的表单。但是,在splash.show_splash()
中调用时,不会发生任何事情(应用程序退出,因为setNextForm
是None
)
如何正确地切换表单
源代码:
class splash(npyscreen.Form):
def afterEditing(self):
self.parentApp.switchFormPrevious()
def create(self):
self.new_splash = self.add(npyscreen.Pager, values=BANNER)
class whatDo(npyscreen.FormBaseNewWithMenus):
def afterEditing(self):
self.parentApp.setNextForm(None)
def create(self):
self.add(npyscreen.TitlePager, name="Hello")
self.m1 = self.new_menu(name="File", shortcut=None)
self.m1.addItemsFromList([
("M1-A", self.open),
("M1-B", self.new),
("M1-C", self.exit_application),
])
self.m2 = self.new_menu(name="Edit", shortcut=None)
self.m2.addItemsFromList([
("M2-A", self.open),
("M2-B", self.new),
])
self.m3 = self.new_menu(name="Other", shortcut=None)
self.m3.addItemsFromList([
("M3-A", self.open),
("M3-A", self.show_splash)
])
def show_splash(self):
self.parentApp.switchForm('SPLASH')
def exit_application(self):
self.parentApp.switchForm(None)
def open(self):
pass
def new(self):
pass
class MyApplication(npyscreen.NPSAppManaged):
def onStart(self):
self.addForm('MAIN', whatDo, name='Main Menu')
self.addForm('SPLASH', splash, lines=30, name='Splash Form')
if __name__ == '__main__':
TestApp = MyApplication().run()
实际上,我通过以下方法解决了这个问题:
这样,您可以通过单击众所周知的“确定”按钮在这两个表单之间切换。我的意思是,这对我很有用
编辑#1: 很抱歉,我在你提出要求10个月后回答了你,但我刚刚开始使用npyscreen
编辑#2: 我必须说,npyscreen是使用UI创建python控制台应用程序的一种非常好的方法。我试着自己做一些类似的事情,回到我痴迷于Python的时候,但是你可能猜到了它是如何进行的
相关问题 更多 >
编程相关推荐