npyscreen |如何编辑其他屏幕/表单,并使用小部件对其进行自定义?

问题描述

嘿,任何人都可以帮助我解决代码,我现在有点卡住了!我正在阅读npyscreen官方文档并没有解决我的问题,所以我没有其他选择发布我的代码并等待它。我解决了所有错误,但问题是我不知道如何使用类编辑自定义屏幕!注意这段代码是用python写的!

这很棘手,它只适用于 python3,并且是认的

#!/usr/bin/env python
import npyscreen,curses
import sys,os

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",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()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)