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()
1username = input(' enter your username: ')
2if username == 'Put Your Username Here':#change this
3 print("checking username")
4 time.sleep(0.5)
5 print("username is right")
6 password = input(' type your password: ')
7 if password == 'Put Your Password Here':#change this
8 time.sleep(0.5)
9 else:
10 exit()
11else:
12 exit()
1class User:
2
3def __init__(self,username,password,basket):
4 self.username=username
5 self.password=password
6 self.basket=basket
7
1 def Login(self):
2 while True:
3 username = raw_input('\nPlease log in by providing your user credentials \nUser Name :')
4
5 if (username == users[0]['username'] or username == users[1]['username']):
6 password = raw_input('Password : ')
7 if (password == users[0]['password'] or password == users[1]['password']):
8 print('Successfully logged in!')
9 print (
10 'Welcome,' + username + '! Please choose of the following options by entering the corresponding menu number.')
11 global LoggedUserName
12 LoggedUserName = username;
13 return True;
14 break;
15 else:
16 print('Your password is not correct. Please try again!')
17 else:
18 print ('Your username is not correct. Please try again!')
19