1import tkinter as tk
2import mysql.connector
3from tkinter import *
4
5
6def submitact():
7
8 user = Username.get()
9 passw = password.get()
10
11 print(f"The name entered by you is {user} {passw}")
12
13 logintodb(user, passw)
14
15
16def logintodb(user, passw):
17
18 # If paswword is enetered by the
19 # user
20 if passw:
21 db = mysql.connector.connect(host ="localhost",
22 user = user,
23 password = passw,
24 db ="College")
25 cursor = db.cursor()
26
27 # If no password is enetered by the
28 # user
29 else:
30 db = mysql.connector.connect(host ="localhost",
31 user = user,
32 db ="College")
33 cursor = db.cursor()
34
35 # A Table in the database
36 savequery = "select * from STUDENT"
37
38 try:
39 cursor.execute(savequery)
40 myresult = cursor.fetchall()
41
42 # Printing the result of the
43 # query
44 for x in myresult:
45 print(x)
46 print("Excecuted successfully")
47
48 except:
49 db.rollback()
50 print("Error occured")
51
52
53root = tk.Tk()
54root.geometry("600x600")
55root.title("LOGIN SYSTEM PYTHON-ANSWER")
56
57
58# Definging the first row
59lblfrstrow = tk.Label(root, text ="USER ID ->", )
60lblfrstrow.place(x = 50, y = 20)
61
62Username = tk.Entry(root, width = 35)
63Username.place(x = 150, y = 20, width = 100)
64
65lblsecrow = tk.Label(root, text ="Password ->")
66lblsecrow.place(x = 50, y = 50)
67
68password = tk.Entry(root, width = 35)
69password.place(x = 150, y = 50, width = 100)
70
71submitbtn = tk.Button(root, text ="Login",
72 bg ='blue', command = submitact)
73submitbtn.place(x = 150, y = 135, width = 55)
74
75root.mainloop()
76
1from tkinter import *
2from functools import partial
3
4def validateLogin(username, password):
5 print("username entered :", username.get())
6 print("password entered :", password.get())
7 return
8
9#window
10tkWindow = Tk()
11tkWindow.geometry('400x150')
12tkWindow.title('Tkinter Login Form - pythonexamples.org')
13
14#username label and text entry box
15usernameLabel = Label(tkWindow, text="User Name").grid(row=0, column=0)
16username = StringVar()
17usernameEntry = Entry(tkWindow, textvariable=username).grid(row=0, column=1)
18
19#password label and password entry box
20passwordLabel = Label(tkWindow,text="Password").grid(row=1, column=0)
21password = StringVar()
22passwordEntry = Entry(tkWindow, textvariable=password, show='*').grid(row=1, column=1)
23
24validateLogin = partial(validateLogin, username, password)
25
26#login button
27loginButton = Button(tkWindow, text="Login", command=validateLogin).grid(row=4, column=0)
28
29tkWindow.mainloop()