import sqlite3 import tkinter as tk from tkinter import * import admin login_db ='login.db' #https://www.pythontutorial.net/tkinter/tkinter-grid/ def connect(): conn=sqlite3.connect("login.db") cur=conn.cursor() cur.execute("CREATE TABLE if NOT exists user(userid INTEGER PRIMARY KEY,name text,password text)") cur.execute("CREATE TABLE if NOT exists admin(adminid INTEGER PRIMARY KEY,name text,password text)") conn.commit() conn.close() def insert(userid,name,password): conn=sqlite3.connect('login.db') cur = conn.cursor() cur.execute('INSERT INTO user VALUES(?,?,?)',(userid,name,password)) conn.commit() conn.close() def authorize_admin(name,password): query = 'INSERT INTO admin VALUES(NULL, ?, ?)' parameters = ("admin","passwd") run_query(query,parameters,login_db) conn=sqlite3.connect(login_db) cur = conn.cursor() if (cur.execute('SELECT * FROM admin WHERE name =? AND password = ?',(name,password))): if cur.fetchone(): window = Tk() window.geometry('800x460') window.configure(bg='#006400') #obj = admin(window) window.mainloop() else: tk.messagebox.showinfo('error','INVALID CREDENTIALS for ADMIN LOGIN') conn.commit() conn.close() def authorize_student(name,password): admin.destroy() # for student login conn=sqlite3.connect('login.db') cur = conn.cursor() if (cur.execute('SELECT * FROM user WHERE name = ? AND password = ?', (name, password))): if cur.fetchone(): window = tk.Tk() window.title('Student_User') window.geometry('700x400') #obj = student(window) window.mainloop() else: tk.messagebox.showinfo('error','INVALID CREDENTIALS for STUDENT LOGIN') conn.commit() conn.close() def run_query(query, parameters = (), db_name=''): with sqlite3.connect(db_name) as conn: cursor = conn.cursor() result = cursor.execute(query, parameters) conn.commit() return result