0

我正在使用 npyscreen,我想了解 switchForm 方法的工作原理。我做了一个从文档和这个问题(没有回答我的问题)中获取的小例子。我的代码:

import npyscreen
import sys

class myEmployeeForm(npyscreen.ActionForm):
   def afterEditing(self):
      self.parentApp.setNextForm('Second')

   def create(self):
      self.myName = self.add(npyscreen.TitleText, name='Name')
      self.myDepartment = self.add(npyscreen.TitleSelectOne, scroll_exit=True, max_height=3, name='Department', values = ['Department 1', 'Department 2', 'Department 3'])
   self.myDate        = self.add(npyscreen.TitleDateCombo, name='Date Employed')

class secondOne(npyscreen.ActionForm):
  def afterEditing(self):
     self.parentApp.setNextForm(None)

  def create(self):
     self.myName        = self.add(npyscreen.TitleText, name='Name')
     self.myDepartment = self.add(npyscreen.TitleSelectOne, scroll_exit=True, max_height=3, name='Department', values = ['Department 1', 'Department 2', 'Department 3'])
     self.myDate        = self.add(npyscreen.TitleDateCombo, name='Date Employed')
     self.add_handlers({"^Q": sys.exit, "^T": self.changingForm('Second')})

  def changingForm(self, name):
     self.parentApp.switchForm(name)

class MyApplication(npyscreen.NPSAppManaged):
   def onStart(self):
    self.addForm('MAIN', myEmployeeForm, name='New Employee')
    self.addForm('Second', secondOne, name='New start')

if __name__ == '__main__':
  TestApp = MyApplication().run()

有人可以向我解释为什么我会收到此错误:

File "/home/MyName/.local/lib/python3.5/site-packages/npyscreen/apNPSApplicationManaged.py", line 81, in switchForm
self._THISFORM.editing = False
AttributeError: 'MyApplication' object has no attribute '_THISFORM'

谢谢您的支持 :)

4

1 回答 1

0

我的错误更多地与 python 相关,而不是与 npyscreen 相关。看这里 在这里输入链接描述 谢谢

于 2017-08-10T09:35:33.423 回答