Hi All,
In this blog, I will tell you , how to make a simple Sign-In/Log-In UI for User. I'm using python27 for this code. Python give you IDLE, which is a good python editor. There are many libraries to make User interface in python, but i m using Tkinter which is python inbuilt library.
Opening a simple window using Tkinter
#!/usr/bin/python
import Tkinter
top = Tkinter.Tk()
# Code to add widgets will go here...
top.mainloop()
Below code is showing simple sign in process in which username "Jagan" and password "123456" is used.
from Tkinter import *
import Tkinter as tk
class Application(Frame):
""" GUI application which can reveal the secret of longevity. """
def __init__(self, master):
""" Initialize the frame. """
Frame.__init__(self, master)
self.grid()
self.create_widgets()
def create_widgets(self):
""" Create button, text, and entry widgets. """
self.userLbl = Label(self, text = "User Name ")
self.userLbl.grid()
self.usernameEntry = Entry(self)
self.usernameEntry.grid(row = 0, column = 1 ,sticky = W)
self.passwrdLbl = Label(self, text = "Password ")
self.passwrdLbl.grid(row = 1, column = 0 ,sticky = W)
self.passEntry = Entry(self, show="*")
self.passEntry.grid(row = 1, column = 1 ,sticky = W)
self.submit_bttn = Button(self, text = "LOGIN", command = self.reveal)
self.submit_bttn.grid(row = 2, column = 1 ,sticky = W)
def create_window(self):
t = tk.Toplevel(self)
t.wm_title("Status")
l = tk.Label(t, text="LOGIN %s" % self.Status)
l.pack(side="top", fill="both", expand=False, padx=100, pady=100)
def reveal(self):
""" Display message based on password. """
user = self.usernameEntry.get()
password = self.passEntry.get()
if user == "Jagan":
if password == "123456":
self.Status = "SUCCESSFULLY"
self.create_window()
else :
self.Status = "FAILED"
self.create_window()
else :
self.Status = "FAILED"
self.create_window()
# main
root = Tk()
root.title("Sample Login UI")
root.geometry("250x150")
app = Application(root)
root.mainloop()
1 Comment(s)