Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- import sqlite3
- import hashlib
- #### USER CLASS ####
- class User:
- def __init__(self, first, last, email, phone, password):
- self.password = password
- self.first = first
- self.last = last
- self.phone = phone
- self.email = email
- def addUser(self):
- userConnect = sqlite3.connect("WoodActually.db")
- cursor = userConnect.cursor()
- userRec = []
- userRec.append(None)
- userRec.append(self.first)
- userRec.append(self.last)
- userRec.append(self.email)
- userRec.append(self.phone)
- userRec.append(self.password)
- cursor.execute("INSERT INTO tblUsers VALUES (?,?,?,?,?,?)", userRec)
- userConnect.commit()
- userRec = []
- userConnect.close()
- def searchUsers(email,password):
- searchConnect = sqlite3.connect("WoodActually.db")
- cursor = searchConnect.cursor()
- searched = cursor.execute('SELECT email,password FROM tblUsers WHERE email=(?) AND password=(?) ',(email,password,)).fetchall()
- result = False
- if searched == []:
- result = False
- else:
- result = True
- return result
- ### TKinter ###
- class main(Frame):
- def __init__(self,master):
- super().__init__(master)
- self.grid()
- self.createwidgets()
- def createwidgets(self):
- self.container = Frame(self, width = 1024,height=768)
- self.container.grid(row=0, column=0, sticky=W+E)
- self.frames = {}
- for f in (loginMenu, loginPage, homePage, storePage, galleryPage, FAQSPage, CreateLoginPage): # defined subclasses of BaseFrame
- frame = f(self.container,self)
- frame.grid(row=2, column=2, sticky=NW+SE)
- self.frames[f] = frame
- self.show_frame(loginMenu)
- def show_frame(self, cls):
- """Show the specified frame.
- Args:
- cls (tk.Frame): The class of the frame to show.
- """
- self.frames[cls].tkraise()
- class loginMenu(Frame):
- ### A GUI application with three buttons. ###
- def __init__(self,master,owner):
- ### Initialise the frame ###
- super().__init__(master)
- self.configure(background = "#496825")
- self.grid()
- self.owner = owner
- self.create_widgets()
- def create_widgets(self):
- ### Create three buttons that do nothing ###
- self.bttn1 = Button(self, text="Login", command = lambda: self.owner.show_frame(loginPage),width=15, height=4)
- self.bttn1.configure(background = "#E1E1E1")
- self.bttn1.grid(row=0)
- self.bttn2 = Button(self, text="Create Login", command = lambda: self.owner.show_frame(CreateLoginPage),width=15, height=4)
- self.bttn2.configure(background = "#E1E1E1")
- self.bttn2.grid(row=3)
- self.bttn3 = Button(self, text="Exit", width=15, height=4,command=self.byebye)
- self.bttn3.configure(background = "#E1E1E1")
- self.bttn3.grid(row=5)
- ## [self.bttn3["text"] = "Same here! "] changes text
- def byebye(self):
- self.owner.master.destroy()
- class CreateLoginPage(Frame):
- def __init__(self,master,owner):
- super().__init__(master)
- self.configure(background = "#496825")
- self.grid()
- self.owner = owner
- self.create_widgets()
- def create_widgets(self):
- ### Creates the inputs for creating a user ###
- self.inst_lbl1 = Label(self, text = "First Name: ", fg="#FFFFFF", background = "#496825")
- self.inst_lbl2 = Label(self, text = "Last Name: ", fg="#FFFFFF", background = "#496825")
- self.inst_lbl3 = Label(self, text = "Email: ", fg="#FFFFFF", background = "#496825")
- self.inst_lbl4 = Label(self, text = "Phone Number: ", fg="#FFFFFF", background = "#496825")
- self.inst_lbl5 = Label(self, text = "Password: ", fg="#FFFFFF", background = "#496825")
- self.inst_lbl1.grid(row = 0, column = 0, columnspan = 2, sticky = W)
- self.inst_lbl2.grid(row = 1, column = 0, columnspan = 2, sticky = W)
- self.inst_lbl3.grid(row = 2, column = 0, columnspan = 2, sticky = W)
- self.inst_lbl4.grid(row = 3, column = 0, columnspan = 2, sticky = W)
- self.inst_lbl5.grid(row = 4, column = 0, columnspan = 2, sticky = W)
- # create entry widgets
- self.first_ent = Entry(self)
- self.last_ent = Entry(self)
- self.email_ent = Entry(self)
- self.phone_ent = Entry(self)
- self.password_ent = Entry(self, show="*")
- self.first_ent.grid(row = 0, column = 2, sticky = W)
- self.last_ent.grid(row = 1, column = 2, sticky = W)
- self.email_ent.grid(row = 2, column = 2, sticky = W)
- self.phone_ent.grid(row = 3, column = 2, sticky = W)
- self.password_ent.grid(row = 4, column = 2, sticky = W)
- # submit button
- self.submit_bttn = Button(self, text = "Submit", command = self.confirm)
- self.submit_bttn.configure(background = "#E1E1E1")
- self.submit_bttn.grid(row=5, column=0)
- self.back_bttn = Button(self, text = "Back", command = self.back)
- self.back_bttn.configure(background = "#E1E1E1")
- self.back_bttn.grid(row=5, column=1)
- def back(self):
- self.owner.show_frame(loginMenu)
- def confirm(self):
- firstContents = self.first_ent.get()
- self.first_ent.delete(0,END)
- lastContents = self.last_ent.get()
- self.last_ent.delete(0,END)
- emailContents = self.email_ent.get()
- self.email_ent.delete(0,END)
- phoneContents = self.phone_ent.get()
- self.phone_ent.delete(0,END)
- passwordContents = self.password_ent.get()
- self.password_ent.delete(0,END)
- passHash = hashlib.sha512(passwordContents.encode("UTF-8")).hexdigest()
- userConnect = sqlite3.connect("WoodActually.db")
- cursor = userConnect.cursor()
- userRec = []
- userRec.append(None)
- userRec.append(firstContents)
- userRec.append(lastContents)
- userRec.append(emailContents)
- userRec.append(phoneContents)
- userRec.append(passHash)
- cursor.execute("INSERT INTO tblUsers VALUES (?,?,?,?,?,?)", userRec)
- userConnect.commit()
- userRec = []
- userConnect.close()
- self.owner.show_frame(loginMenu)
- class loginPage(Frame):
- def __init__(self,master,owner):
- super().__init__(master)
- self.configure(background = "#496825")
- self.grid()
- self.owner = owner
- self.create_widgets()
- def create_widgets(self):
- ### Creates the inputs for logging into the app ###
- self.inst_lbl1 = Label(self, text = "Email: ", fg="#FFFFFF", background = "#496825")
- self.inst_lbl2 = Label(self, text = "Password: ", fg="#FFFFFF", background = "#496825")
- self.inst_lbl1.grid(row = 0, column = 0, columnspan = 2, sticky = W)
- self.inst_lbl2.grid(row = 1, column = 0, columnspan = 2, sticky = W)
- # create entry widgets
- self.user_ent = Entry(self)
- self.pw_ent = Entry(self, show="*")
- self.user_ent.grid(row = 0, column = 2, sticky = W)
- self.pw_ent.grid(row = 1, column = 2, sticky = W)
- # create submit button
- self.submit_bttn = Button(self, text = "Submit", command = self.submit)
- self.submit_bttn.configure(background = "#E1E1E1")
- self.submit_bttn.grid(row=5)
- self.back_bttn = Button(self, text = "Back", command = self.back)
- self.back_bttn.configure(background = "#E1E1E1")
- self.back_bttn.grid(row=5, column=1)
- def back(self):
- self.owner.show_frame(loginMenu)
- def submit(self):
- UserContents = self.user_ent.get()
- self.user_ent.delete(0,END)
- PwContents = self.pw_ent.get()
- passHash = hashlib.sha512(PwContents.encode("UTF-8")).hexdigest()
- self.pw_ent.delete(0,END)
- searchConnect = sqlite3.connect("WoodActually.db")
- cursor = searchConnect.cursor()
- searched = cursor.execute('SELECT email,password FROM tblUsers WHERE email=(?) AND password=(?) ',(UserContents,passHash)).fetchall()
- result = False
- if searched == []:
- result = False
- self.owner.show_frame(loginMenu)
- else:
- result = True
- self.owner.show_frame(homePage)
- class homePage(Frame):
- def __init__(self,master,owner):
- super().__init__(master)
- self.configure(background = "#496825")
- self.grid()
- self.owner = owner
- self.create_widgets()
- def create_widgets(self):
- self.bttn1 = Button(self, text="Store", command = lambda: self.owner.show_frame(storePage))
- self.bttn1.configure(background = "#E1E1E1")
- self.bttn1.grid(row=0, column = 0, columnspan=2, sticky=NSEW)
- self.bttn2 = Button(self, text="Gallery", command = lambda: self.owner.show_frame(galleryPage))
- self.bttn2.configure(background = "#E1E1E1")
- self.bttn2.grid(row=0, column = 2, columnspan=2, sticky=NSEW)
- self.bttn3 = Button(self, text="Home", command = lambda: self.owner.show_frame(homePage))
- self.bttn3.configure(background = "#E1E1E1")
- self.bttn3.grid(row=0, column = 4, columnspan=2, sticky=NSEW)
- self.bttn4 = Button(self, text="FAQs", command = lambda: self.owner.show_frame(FAQSPage))
- self.bttn4.configure(background = "#E1E1E1")
- self.bttn4.grid(row=0, column = 6, columnspan=2, sticky=NSEW)
- self.bttn5 = Button(self, text="Exit", command=self.byebye)
- self.bttn5.configure(background = "#E1E1E1")
- self.bttn5.grid(row=0, column = 8, columnspan=2, sticky=NSEW)
- ############### TEXT ##################
- self.inst_lbl1 = Label(self, text = "Wood Actually was created in 2010. We are a small family based firm, who pride ourselves in producing quality chainsaw carvings in the North East of England.", fg="#FFFFFF")
- self.inst_lbl1.configure(background = "#496825")
- self.inst_lbl1.grid(row = 1, column = 0, columnspan = 10, sticky = W)
- def byebye(self):
- self.owner.master.destroy()
- class storePage(Frame):
- def __init__(self,master,owner):
- super().__init__(master)
- self.configure(background = "#496825")
- self.grid()
- self.owner = owner
- self.create_widgets()
- def create_widgets(self):
- self.bttn1 = Button(self, text="Store", command = lambda: self.owner.show_frame(storePage))
- self.bttn1.configure(background = "#E1E1E1")
- self.bttn1.grid(row=0, column = 0, columnspan=2, sticky=NSEW)
- self.bttn2 = Button(self, text="Gallery", command = lambda: self.owner.show_frame(galleryPage))
- self.bttn2.configure(background = "#E1E1E1")
- self.bttn2.grid(row=0, column = 2, columnspan=2, sticky=NSEW)
- self.bttn3 = Button(self, text="Home", command = lambda: self.owner.show_frame(homePage))
- self.bttn3.configure(background = "#E1E1E1")
- self.bttn3.grid(row=0, column = 4, columnspan=2, sticky=NSEW)
- self.bttn4 = Button(self, text="FAQs", command = lambda: self.owner.show_frame(FAQSPage))
- self.bttn4.configure(background = "#E1E1E1")
- self.bttn4.grid(row=0, column = 6, columnspan=2, sticky=NSEW)
- self.bttn5 = Button(self, text="Exit", command=self.byebye)
- self.bttn5.configure(background = "#E1E1E1")
- self.bttn5.grid(row=0, column = 8, columnspan=2, sticky=NSEW)
- def byebye(self):
- self.owner.master.destroy()
- class galleryPage(Frame):
- def __init__(self,master,owner):
- super().__init__(master)
- self.configure(background = "#496825")
- self.grid()
- self.owner = owner
- self.create_widgets()
- def create_widgets(self):
- self.bttn1 = Button(self, text="Store", command = lambda: self.owner.show_frame(storePage))
- self.bttn1.configure(background = "#E1E1E1")
- self.bttn1.grid(row=0, column = 0, columnspan=2, sticky=NSEW)
- self.bttn2 = Button(self, text= "Gallery", command = lambda: self.owner.show_frame(galleryPage))
- self.bttn2.configure(background = "#E1E1E1")
- self.bttn2.grid(row=0, column = 2, columnspan=2, sticky=NSEW)
- self.bttn3 = Button(self, text="Home", command = lambda: self.owner.show_frame(homePage))
- self.bttn3.configure(background = "#E1E1E1")
- self.bttn3.grid(row=0, column = 4, columnspan=2, sticky=NSEW)
- self.bttn4 = Button(self, text="FAQs", command = lambda: self.owner.show_frame(FAQSPage))
- self.bttn4.configure(background = "#E1E1E1")
- self.bttn4.grid(row=0, column = 6, columnspan=2, sticky=NSEW)
- self.bttn5 = Button(self, text="Exit", command=self.byebye)
- self.bttn5.configure(background = "#E1E1E1")
- self.bttn5.grid(row=0, column = 8, columnspan=2, sticky=NSEW)
- #####################################################
- path = "paw.gif"
- self.img = PhotoImage(file = path)
- panel = Label(self, image = self.img)
- panel.grid(row=1, column=0, columnspan=10)
- #####################################################
- pathSheep = "sheep.gif"
- self.Img2 = PhotoImage(file = pathSheep)
- panel2 = Label(self, image = self.Img2)
- panel2.grid(row=1, column=1, columnspan=10)
- #####################################################
- def byebye(self):
- self.owner.master.destroy()
- class FAQSPage(Frame):
- def __init__(self,master,owner):
- super().__init__(master)
- self.configure(background = "#496825")
- self.grid()
- self.owner = owner
- self.create_widgets()
- def create_widgets(self):
- self.bttn1 = Button(self, text="Store", command = lambda: self.owner.show_frame(storePage))
- self.bttn1.configure(background = "#E1E1E1")
- self.bttn1.grid(row=0, column = 0, columnspan=2, sticky=NSEW)
- self.bttn2 = Button(self, text="Gallery", command = lambda: self.owner.show_frame(galleryPage))
- self.bttn2.configure(background = "#E1E1E1")
- self.bttn2.grid(row=0, column = 2, columnspan=2, sticky=NSEW)
- self.bttn3 = Button(self, text="Home", command = lambda: self.owner.show_frame(homePage))
- self.bttn3.configure(background = "#E1E1E1")
- self.bttn3.grid(row=0, column = 4, columnspan=2, sticky=NSEW)
- self.bttn4 = Button(self, text="FAQs", command = lambda: self.owner.show_frame(FAQSPage))
- self.bttn4.configure(background = "#E1E1E1")
- self.bttn4.grid(row=0, column = 6, columnspan=2, sticky=NSEW)
- self.bttn5 = Button(self, text="Exit", command=self.byebye)
- self.bttn5.configure(background = "#E1E1E1")
- self.bttn5.grid(row=0, column = 8, columnspan=2, sticky=NSEW)
- ################ TEXT ################
- self.inst_lbl1 = Label(self, text = "Bears.", fg="#FFFFFF")
- self.inst_lbl1.configure(background = "#496825")
- self.inst_lbl1.grid(row = 1, column = 0, columnspan = 10, sticky = W)
- def byebye(self):
- self.owner.master.destroy()
- ##### MAIN #####
- root = Tk()
- root.title("Wood Actually")
- root.geometry("1024x768")
- root.resizable(False,False)
- root.configure(background = "#496825")
- # #496825 #GREEN
- # #E1E1E1 #Whitish?
- app = main(root)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement