introduction to event handling

 

from tkinter import *
from PIL import ImageTk, Image
root = Tk()
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")
def close_app():
root2.destroy()
bt["state"] = ["normal"]
def n_w():
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="#18705e", 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.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.place(x=200,y=150)
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()







Comments