Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import MySQLdb
- from tkinter import *
- import tkinter.messagebox
- import hashlib
- class MainWindow:
- def __init__(self,master):
- self.master=master
- self.master.title("Online Quiz")
- self.master.config(bg = "powder blue")
- f = Frame(self.master, height =750,width = 600,bg="powder blue")
- f.propagate(0)
- f.pack()
- self.regi = Button(f, text="Register",command = self.c_reg)
- self.login = Button(f, text="Login",command = self.c_login)
- self.regi.place(x=135,y=400)
- self.login.place(x=250,y=400)
- def c_reg(self):
- self.newWindow = Toplevel(self.master)
- self.app = Register(self.newWindow)
- def c_login(self):
- self.login = Toplevel(self.master)
- self.log = Login(self.login)
- class Register:
- def __init__(self,master):
- self.master=master
- self.master.title("Online Quiz")
- self.master.config(bg = "powder blue")
- f = Frame(self.master, height =750,width = 600,bg="powder blue")
- f.propagate(0)
- f.pack()
- #-----------------------Labels----------------------
- self.name = Label(text = "First Name : ")
- self.lname = Label(text = "Last name : ")
- self.email = Label(text = "Email id : ")
- self.uname = Label(text = "Username :")
- self.pw = Label(text = "Enter password : ")
- self.cpw = Label(text = "Confirm password : ")
- #----------------------Textboxes----------------------
- self.tname = Entry(f, width=30)
- self.tlname = Entry(f, width=30)
- self.temail = Entry(f, width=30)
- self.tuname = Entry(f, width=30)
- self.tpw = Entry(f, width=30,show="*")
- self.tcpw = Entry(f, width=30,show="*")
- #----------------------Button-------------------------
- self.submit = Button(f, text="Submit",command = self.c_submit)
- self.cancel = Button(f, text="Cancel",command = self.c_cancel)
- #----------------------Position----------------------
- self.name.place(x=50 ,y=100)
- self.tname.place(x=200 ,y=100)
- self.lname.place(x=50 ,y=150)
- self.tlname.place(x=200 ,y=150)
- self.email.place(x=50 ,y=200)
- self.temail.place(x=200 ,y=200)
- self.uname.place(x=50 ,y=250)
- self.tuname.place(x=200 ,y=250)
- self.pw.place(x=50 ,y=300)
- self.tpw.place(x=200 ,y=300)
- self.cpw.place(x=50 ,y=350)
- self.tcpw.place(x=200 ,y=350)
- self.submit.place(x=135,y=400)
- self.cancel.place(x=250,y=400)
- #----------Action after Submit button is pressed---------------
- def c_submit(self):
- conn = MySQLdb.connect(host='localhost', database='world', user='root', password='root')
- cursor = conn.cursor()
- name = self.tname.get()
- lname = self.tlname.get()
- email = self.temail.get()
- uname = self.tuname.get()
- pw = self.tpw.get()
- conpw = self.tcpw.get()
- p = hashlib.sha1((uname[:5]+pw).encode('utf-8')).hexdigest()
- try:
- s = "insert into reg2(name,lname,email,uname,p) values('%s','%s','%s','%s','%s')"
- arg = (name,lname,email,uname,p)
- cursor.execute(s % arg)
- conn.commit()
- except:
- conn.rollback()
- cursor.close()
- conn.close()
- def c_cancel(self):
- pass
- class Login:
- def __init__(self, master):
- f = Frame(master, height=350, width=600)
- f.propagate(0)
- f.pack()
- self.l1 = Label(text="Enter Username: ")
- self.e1 = Entry(f, width=25)
- self.l2 = Label(text="Enter Password: ")
- self.e2 = Entry(f, width=25, show="*")
- self.b1 = Button(f, text="Signup", command=self.clicked)
- self.b2 = Button(f, text="Cancel", command=self.cancelLogin)
- self.l1.place(x=50, y=100)
- self.e1.place(x=150, y=100)
- self.l2.place(x=50, y=150)
- self.e2.place(x=150, y=150)
- self.b1.place(x=170, y=200)
- self.b2.place(x=250, y=200)
- def cancelLogin(self):
- exit(0)
- #------------------------------------------signup button---------------------------------------------
- def clicked(self):
- conn = MySQLdb.connect(host='localhost', database='world', user='root', password='veer1811')
- cursor = conn.cursor()
- u = self.e1.get()
- pw = self.e2.get()
- #password hash
- p = hashlib.sha1((u[:5]+pw).encode('utf-8')).hexdigest()
- print(p)
- try:
- s = "insert into reg1(username, pw) values('%s', '%s')"
- arg = (u, p)
- cursor.execute(s % arg)
- conn.commit()
- except:
- conn.rollback()
- cursor.close()
- conn.close()
- root = Tk()
- RegObj = MainWindow(root)
- root.mainloop()
Add Comment
Please, Sign In to add comment