嘿,任何人都可以帮助我处理这段代码,我现在有点卡住了!我正在阅读 npyscreen 官方文档,它并没有解决我的问题,所以我没有其他选择发布我的代码,只是等待它。我解决了所有错误,但问题是我不知道如何使用类编辑自定义屏幕!注意这段代码是用python写的!
这很棘手,它只适用于python3,并且默认
#!/usr/bin/env python
import npyscreen, curses
import sys, os
# I added it for fun, renaming the terminal
sys.stdout.write(b'\33]0;Terminal Executable\a')
sys.stdout.flush()
class ObjectForm(npyscreen.NPSAppManaged):
def onStart(self):
# When Application starts, set up the Forms that will be used.
# These two forms are persistent between each edit.
self.addForm("MAIN", MainForm, name="Screen 1", color="IMPORTANT",)
self.addFormClass("SECOND", MainForm, name="Screen 2", color="WARNING",)
def onCleanExit(self):
npyscreen.notify_wait(None)
# You might put anything here to show if your leaving.
# But I have wrote on_ok and on_cancel, _pen_*22
def change_form(self, name):
# Switch forms. NB. Do *not* call the .edit() method.
# Else the intrepeter will not understant and will not work!
self.switchForm(name)
# By default the application keeps track of every form visited.
# There's no harm in this, but we don't need it so:
self.resetHistory()
class MainForm(npyscreen.ActionForm):
def create(self):
pass
def on_ok(self):
# Swith forms in npyscreen_curses, Main, Second
self.parentApp.setNextForm("SECOND")
def on_cancel(self):
# Asks the user if she/he wants to leave the program.
exiting = npyscreen.notify_yes_no("Are you sure you want to cancel?", "Exit Program")
if (exiting):
self.parentApp.setNextForm(None)
else:
pass
def change_forms(self, *args, **keywords):
if self.name == "Screen 1":
change_to = "SECOND"
else:
change_to = "MAIN"
# Tell the MyTestApp object to change forms.
self.parentApp.change_form(change_to)
def main():
# Changes the name, and runs the program
main = ObjectForm()
main.run()
if __name__ == '__main__':
main()