Python Forum
Help with passing values in npyscreen
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with passing values in npyscreen
#1
Hello,

I'm playing around with npyscreen to make my terminal application look nicer and be more user friendly.
I'm trying to take in the user's input from self.user and seld.password and carry them over to my validate function so it can go to the menu screen.

Am I passing the values correctly? If not, how do I?

Thanks I advance.

TUITest.py
import npyscreen

class LoginForm(npyscreen.Form):
    def afterEditing(self):
        self.parentApp.setNextForm(None)

    def create(self):
        self.user = self.add(npyscreen.TitleText, name='Name:')
        self.password = self.add(npyscreen.TitleText, name='Password:')

        user = self.user
        password = self.password
       validate(user,password)


class MyApplication(npyscreen.NPSAppManaged):
   def onStart(self):
       self.addForm('MAIN', LoginForm, name='Log In')

if __name__ == '__main__':
   TestApp = MyApplication().run()
My Validate Function
#---------------------------------------------------------------
#                Validate Function -> Validates user 
#---------------------------------------------------------------
#Pass in user and password variables from login function
#Check if the user is valid (registered in database) -> Give access to inventory program
#close login screen and open menu screen 
#If user is not valid -> return to login or have invalid credentials popup
#-->TODO: Write the user and current date to a file to keep track of logins
def validate(user, password):
    if StandardUsers().get(user) == password:
        print('Success! You are now logged in as: ' + user)
        #mainMenu()
        return True

    if SuperUsers().get(user) == password:
        print('Success! You are now logged in as: ' + user)
        #adminMenu()
        
    else:
        return
#---------------------------------------------------------------
Side notes:
This was my working terminal version and I want to carry it over to npyscreen so it looks nicer.
This is what I'm trying to achieve but with a fancy TUI

#---------------------------------------------------------------
#                        Login Menu
#---------------------------------------------------------------
def login():
    while True:
        print('=============================\n''\tLogin\n''=============================')
        user = input("Enter your name (Case Sensitive): ")
        password = input("Enter your password: ")
        #If the credentials are validated -> Run validate function -> Go to according menu
        #Else -> Print error message and show login screen again
        if validate(user, password):
            break
        else:
            print('You are not registered to use this program')
#---------------------------------------------------------------

#---------------------------------------------------------------
#                Validate Function -> Validates user 
#---------------------------------------------------------------
#Pass in user and password variables from login function
#Check if the user is valid (registered in database) -> Give access to inventory program 
#If user is not valid -> return to login
#-->TODO: Write the user and current date to a file to keep track of logins
def validate(user, password):
    if StandardUsers().get(user) == password:
        print('Success! You are now logged in as: ' + user)
        mainMenu()
        return True

    if SuperUsers().get(user) == password:
        print('Success! You are now logged in as: ' + user)
        adminMenu()
        
    else:
        return
#---------------------------------------------------------------
Reply


Messages In This Thread
Help with passing values in npyscreen - by Extra - May-14-2022, 02:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Solved]Return values from npyscreen Extra 2 1,250 Oct-09-2022, 07:19 PM
Last Post: Extra
  Passing Values of Dictionaries to Function & Unable to Access Them firebird 3 2,668 Aug-03-2019, 10:25 PM
Last Post: firebird

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020