Making Login Window And how hide the background text and password Powercombo

 

from tkinter import *
from PIL import ImageTk,Image
#close all the code inside the project_1 function
def project_1():
root=Tk()
"""
This bwlow state used for creating main window in the centre of the laptop screen
"""
app_width = 600
app_height = 600
scr_width = root.winfo_screenwidth()
scr_height = root.winfo_screenheight()
xcord = (scr_width / 2) - (app_width / 2)
ycord = (scr_height / 2) - (app_height / 2)
root.geometry("%dx%d+%d+%d" % (app_width, app_height, xcord, ycord))
root.configure(background="#979069")
"""
This below close_app function active when we close the "login window"
"""

def close_app():
root2.destroy()
bt["state"] = ["normal"]
"""
this below function active when we move cursor to user id entry box basicaly related to "event handling"
"""
def c_t(e):
if v_1.get() == "user id":
v_1.delete(0, END)
"""This below function is activated when when we move cursor on password entry box its became empty
"""
def c_t_2(e1):

if v_2.get() == "password":
v_2.delete(0, END)
v_2.config(show="*")
"""
Creating new window for Login
"""
def n_w():
global v_1, v_2
global root2
bt['state'] = ['disable']
root2 = Toplevel(root)
root2.protocol("WM_DELETE_WINDOW", close_app)
app_width = 600
app_height = 400
scr_width = root2.winfo_screenwidth()
scr_height = root2.winfo_screenheight()
xcord = (scr_width / 2) - (app_width / 2)
ycord = (scr_height / 2) - (app_height / 2)
root2.geometry("%dx%d+%d+%d" % (app_width, app_height, xcord, ycord))
root2.title("General Store")
root2.iconbitmap("E:\\python projects\\shops_awP_icon.ico")
back_image = Image.open("C:\\Users\\Fahad Ali Khan\\Desktop\\a.jpg")
set_image = ImageTk.PhotoImage(back_image)
l1 = Label(root2, image=set_image).place(x=0, y=0, relwidth=1, relheight=1)
welcome_note_2 = Label(root2, text="Login", bg="#1c1750", fg="#98bcc2", bd=6, width=100, relief=RAISED,
font="Helvetica 12 bold", justify=CENTER)
welcome_note_2.pack(fill="y")
u_n = StringVar()
u_n.set("user id")
pas = StringVar()
pas.set("password")
v_1 = Entry(root2, textvariable=u_n, bg="#1c1750", fg="#98bcc2", bd=6, width=20, relief=RAISED,font="Helvetica 12 bold", justify=CENTER)
# v_1.bind("<Button-1>",c_t)
#calling event handling funtion on FocusIn
v_1.bind("<FocusIn>", c_t)
v_1.place(x=200, y=100)
v_2 = Entry(root2, textvariable=pas, bg="#1c1750", fg="#98bcc2", bd=6, width=20, relief=RAISED,font="Helvetica 12 bold", justify=CENTER)
# v_2.bind("<Button-1>", c_t)
v_2.bind("<FocusIn>", c_t_2)
v_2.place(x=200, y=150)

# writing function to show or hide password
# important
def show_pass():

if v_2.cget("show") == "":
v_2.config(show='*')
pass_show.config(text='Show Password')
else:
v_2.config(show='')
pass_show.config(text='Hide Password')

pass_show = Button(root2, text="Show Password", command=show_pass, bg="#1c1750", fg="#98bcc2", bd=0, relief=RAISED,justify=CENTER)
pass_show.place(x=395, y=155)
#login button

l_btn=Button(root2,text="Login",bg="#1c1750", fg="#98bcc2", bd=6, width=20,relief=RAISED,font="Helvetica 12 bold", justify=CENTER)
l_btn.pack(pady=170)

root2.maxsize(600, 400)
root2.minsize(600, 400)
root2.mainloop()

root.title("Shop Manager")
root.iconbitmap("E:\\python projects\\shops_awP_icon.ico")
welcome_note = Label(root, text="Welcome To The Shop Manager", bg="#a2812a", bd=6, width=100, relief=RAISED,
font="Helvetica 12 bold", justify=CENTER).pack()
bt = Button(root, text="Log In", command=n_w, bg="#a2812a", bd=6, width=10, relief=RIDGE, font="Helvetica 12 bold",
justify=CENTER)
bt.pack(pady=3)
bt2 = Button(root, text="Exit", command=root.destroy, bg="#a2812a", bd=6, width=10, relief=RIDGE,
font="Helvetica 12 bold", justify=CENTER)
bt2.pack(side=BOTTOM, pady=3)



root.mainloop()
project_1()

 

Comments