title: Python npyscreen: How to launch form from button press?
body: <p>I've googled, read the docs (kinda hard for me to understand), googled some more, looked at examples, and I just can't find an answer. Maybe there is no way to do it.</p>
  <pre><code>self.button = self.add(npyscreen.Button, name=&quot;Button&quot;)
  </code></pre>
  <p>This produces a button but it seems to be more of a True or False selector. Can one do something on-press with it, like launch another form?</p>
  <p>Below is a working example application I put together to get started. Can you show me how to make that button launch the second form? If it can't be done with a button, is there another way to essentially do the same thing?</p>
  <p>Ultimately I would like the first menu to display a list of options that upon selecting one of them, would open up a second form. When done in the second form, they would be directed back to the main menu to select further options as needed or exit the application. I think I have everything I need worked out except this. Thanks for your help!</p>
  <pre><code>#!/usr/bin/python
  # encoding=utf8
  
  import npyscreen
  
  # This is a form object
  class WizardFormMain(npyscreen.ActionForm, npyscreen.SplitForm, npyscreen.FormWithMenus):
    def create(self):
  
      self.button = self.add(npyscreen.Button, name=&quot;Button&quot;) # Make this button go to FORM2
   
      # Since we are inheriting the npyscreen.FormWithMenus class we can use menus, this will add an option to the menu to exit the program
      self.menu = self.new_menu(name=&quot;Main Menu&quot;, shortcut='^M')
      self.menu.addItem(&quot;Exit Program&quot;, self.exit, &quot;^X&quot;)
    # END DEF
      
    def exit(self):
      self.parentApp.switchForm(None) # causes the app to exit on OK
    # END DEF
  
    # Save data to conf file and Go back to first form...
    def on_ok(self):
      npyscreen.notify_confirm(&quot;OK Pressed, going to FORM2 now.&quot;, title=&quot;Notice&quot;, wrap=True, wide=True, editw=1)
      self.parentApp.setNextForm('FORM2')
    # END DEF
  
    def on_cancel(self):
      self.parentApp.setNextForm(None) # Also exit's the program
    # END DEF
  
  # END CLASS
  
  # FORM2
  class WizardForm2(npyscreen.ActionForm, npyscreen.SplitForm, npyscreen.FormWithMenus):
    def create(self):
  
      self.name = self.add( npyscreen.TitleText, name=&quot;Username: &quot; )
      self.passwd = self.add( npyscreen.TitleText, name=&quot;Password: &quot; )
  
    # Save data to conf file and Go back to first form...
    def on_ok(self):
      npyscreen.notify_confirm(&quot;Saved! Going back to main form&quot;, title=&quot;OK Presed&quot;, wrap=True, wide=True, editw=1)
      self.parentApp.setNextForm('MAIN')
    # END DEF
  
    def on_cancel(self):
      npyscreen.notify_confirm(&quot;NOT Saved, going back to main form&quot;, title=&quot;OK Presed&quot;, wrap=True, wide=True, editw=1)
      self.parentApp.setNextForm('MAIN') # Back to main form
    # END DEF
  # END CLASS
  
  # This is the Wizards form manager function
  class WizardApp(npyscreen.NPSAppManaged):
    def onStart(self):
      self.addForm('MAIN', WizardFormMain, name = &quot;First Form!&quot;, lines=20, columns=60, draw_line_at=16 )
      self.addForm('FORM2', WizardForm2, name = &quot;Second Form!&quot;, lines=20, columns=60, draw_line_at=16 )
    # END DEF
  # END CLASS
  
  
  if ( __name__ == &quot;__main__&quot;):
    wizard = WizardApp().run()
  </code></pre>
  <p><a href="https://i.stack.imgur.com/ETsiB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ETsiB.png" alt="MAIN form OK  " /></a>
  <a href="https://i.stack.imgur.com/yOnQE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yOnQE.png" alt="Main Form     " /></a>
  <a href="https://i.stack.imgur.com/6tcYj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6tcYj.png" alt="MAIN form menu" /></a>
  <a href="https://i.stack.imgur.com/MQ3bD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MQ3bD.png" alt="SECOND form   " /></a></p>