Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Create a simple login application for MAC

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.68k
    Comment on it

    Hi all,

    An app user has to login before navigating to the any screen. In our app user will enter username and password for login, so we need two textfield and a button two submit. so lets start and follow these steps.

    1) First step is to create a non resizable window 600X400 :-

    1. #!/usr/bin/python
    2.  
    3. import sys
    4. if sys.version_info < (3, 0):
    5. # Python 2
    6. import Tkinter as tk
    7. else:
    8. # Python 3
    9. import tkinter as tk
    10.  
    11. root = tk.Tk()
    12. root.title("Mac Application")
    13. root.resizable(width=False, height=False)
    14. root.geometry('600x400')
    15. tk.mainloop()

    2) Now create user interface for app : We added two labels , textfield and a button , to create UI we used tkinter library of python.

    1. #!/usr/bin/python
    2.  
    3. import sys
    4. if sys.version_info < (3, 0):
    5. # Python 2
    6. import Tkinter as tk
    7. else:
    8. # Python 3
    9. import tkinter as tk
    10.  
    11. username = "Jagan"
    12. password = "123456"
    13.  
    14. class Login:
    15.  
    16. def __init__(self, name, password):
    17. self.name = name
    18. self.password = password
    19. lbl1 = tk.Label( root, text="Username :").pack()
    20. self.e1 = tk.Entry(root, bd =5)
    21. self.e1.pack()
    22. lbl2 = tk.Label( root, text="Password :").pack()
    23. self.e2 = tk.Entry(root,show="*", bd =5)
    24. self.e2.pack()
    25. btn = tk.Button(root, text="Login",command=self.loginAction).pack()
    26. self.lbl = tk.Label( root, text="")
    27. self.lbl.pack()
    28.  
    29. root = tk.Tk()
    30. root.title("Mac Application")
    31. root.resizable(width=False, height=False)
    32. root.geometry('600x400')
    33.  
    34. obj = Login(username, password)
    35. tk.mainloop()

    3) Now add action to button and show the status of user action below :-

    1. #!/usr/bin/python
    2.  
    3. import sys
    4. if sys.version_info < (3, 0):
    5. # Python 2
    6. import Tkinter as tk
    7. else:
    8. # Python 3
    9. import tkinter as tk
    10.  
    11. username = "Jagan"
    12. password = "123456"
    13.  
    14. class Login:
    15.  
    16. def __init__(self, name, password):
    17. self.name = name
    18. self.password = password
    19. lbl1 = tk.Label( root, text="Username :").pack()
    20. self.e1 = tk.Entry(root, bd =5)
    21. self.e1.pack()
    22. lbl2 = tk.Label( root, text="Password :").pack()
    23. self.e2 = tk.Entry(root,show="*", bd =5)
    24. self.e2.pack()
    25. btn = tk.Button(root, text="Login",command=self.loginAction).pack()
    26. self.lbl = tk.Label( root, text="")
    27. self.lbl.pack()
    28.  
    29. def loginAction(self):
    30.  
    31.      if self.name == self.e1.get() and self.password == self.e2.get():
    32.          self.lbl.config(text='Succesfully Logged In !!')
    33.      else:
    34.          self.lbl.config(text='Username or password is incorrect')
    35.  
    36.  
    37. root = tk.Tk()
    38. root.title("Mac Application")
    39. root.resizable(width=False, height=False)
    40. root.geometry('600x400')
    41.  
    42. obj = Login(username, password)
    43. tk.mainloop()
    44.     
    45.  
    46.  
    47.  
    48.  
    49.  


    Now you can run this app from your command line and use Jagan as username and 123456 as password to login.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: