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 :-
#!/usr/bin/python
import sys
if sys.version_info < (3, 0):
# Python 2
import Tkinter as tk
else:
# Python 3
import tkinter as tk
root = tk.Tk()
root.title("Mac Application")
root.resizable(width=False, height=False)
root.geometry('600x400')
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.
#!/usr/bin/python
import sys
if sys.version_info < (3, 0):
# Python 2
import Tkinter as tk
else:
# Python 3
import tkinter as tk
username = "Jagan"
password = "123456"
class Login:
def __init__(self, name, password):
self.name = name
self.password = password
lbl1 = tk.Label( root, text="Username :").pack()
self.e1 = tk.Entry(root, bd =5)
self.e1.pack()
lbl2 = tk.Label( root, text="Password :").pack()
self.e2 = tk.Entry(root,show="*", bd =5)
self.e2.pack()
btn = tk.Button(root, text="Login",command=self.loginAction).pack()
self.lbl = tk.Label( root, text="")
self.lbl.pack()
root = tk.Tk()
root.title("Mac Application")
root.resizable(width=False, height=False)
root.geometry('600x400')
obj = Login(username, password)
tk.mainloop()
3) Now add action to button and show the status of user action below :-
#!/usr/bin/python
import sys
if sys.version_info < (3, 0):
# Python 2
import Tkinter as tk
else:
# Python 3
import tkinter as tk
username = "Jagan"
password = "123456"
class Login:
def __init__(self, name, password):
self.name = name
self.password = password
lbl1 = tk.Label( root, text="Username :").pack()
self.e1 = tk.Entry(root, bd =5)
self.e1.pack()
lbl2 = tk.Label( root, text="Password :").pack()
self.e2 = tk.Entry(root,show="*", bd =5)
self.e2.pack()
btn = tk.Button(root, text="Login",command=self.loginAction).pack()
self.lbl = tk.Label( root, text="")
self.lbl.pack()
def loginAction(self):
if self.name == self.e1.get() and self.password == self.e2.get():
self.lbl.config(text='Succesfully Logged In !!')
else:
self.lbl.config(text='Username or password is incorrect')
root = tk.Tk()
root.title("Mac Application")
root.resizable(width=False, height=False)
root.geometry('600x400')
obj = Login(username, password)
tk.mainloop()
Now you can run this app from your command line and use Jagan as username and 123456 as password to login.
0 Comment(s)