Page 56 - Phyton_GUIprogrammingwithTkinter
P. 56

P a ge  | 47


               Login Form Code

                 from tkinter import *
                 from tkinter import messagebox
                 import mysql.connector as mysql

                 def login ():
                     uname=username.get ()
                     pw=password.get ()
                     if (uname==""or pw==""):
                         messagebox.showinfo("Login Status", "Please enter the
                 correct username and password")
                     elif(uname==username.get () or pw==password.get()):
                         messagebox.showinfo("Login Status", "Correct username and
                 password")
                         root.destroy()
                         import register_pbt2
                     else:
                         con=mysql.connect(host="localhost", user="root",
                 password="", database="employee")
                         cursor=con.cursor()
                         cursor.execute("select * from user")

                         con.close();

                 root = Tk ()
                 root.title("Login Form")

                 canvas1 = Canvas (root, width = 350, height = 280)
                 Canvas1 = Canvas(root)
                 canvas1.pack()

                 subtitle = Label (root, text="Please enter your details to login”,
                 font=("Helvetica",12), foreground = '#0000e0'). place (x=55, y=8)

                 #Username
                 label_Uname= Label (root, text="Username*”, font=("Helvetica",12))
                 label_Uname.place(x=130, y=70)
                 username = Entry (root, font=("Helvetica",15), bg="white")
                 username.place(x=50, y=100, width=250, height=20)

                 #Password
                 label_pw= Label (root, text="Password*", font=("arial",12))
                 label_pw.place(x=130,y=130)
                 password = Entry (root, font=("Helvetica",12), bg="white",show='*')
                 password.place(x=50, y=160, width=250, height=20)

                 #Button
                 submit = Button (root, cursor="hand2", text="Login",bd=2,
                 font=("Helvetica",12),width=12, activebackground='#002e63’,
                 activeforeground='white',command=login).place(x=115,y=210)

                 root.mainloop()
   51   52   53   54   55   56   57   58   59   60   61