Advertisement
Guest User

Untitled

a guest
Apr 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.57 KB | None | 0 0
  1. from tkinter import *
  2. import sqlite3
  3. import hashlib
  4.  
  5. #### USER CLASS ####
  6.  
  7. class User:
  8.  
  9. def __init__(self, first, last, email, phone, password):
  10. self.password = password
  11. self.first = first
  12. self.last = last
  13. self.phone = phone
  14. self.email = email
  15.  
  16. def addUser(self):
  17.  
  18. userConnect = sqlite3.connect("WoodActually.db")
  19. cursor = userConnect.cursor()
  20. userRec = []
  21. userRec.append(None)
  22. userRec.append(self.first)
  23. userRec.append(self.last)
  24. userRec.append(self.email)
  25. userRec.append(self.phone)
  26. userRec.append(self.password)
  27. cursor.execute("INSERT INTO tblUsers VALUES (?,?,?,?,?,?)", userRec)
  28. userConnect.commit()
  29. userRec = []
  30. userConnect.close()
  31.  
  32.  
  33. def searchUsers(email,password):
  34. searchConnect = sqlite3.connect("WoodActually.db")
  35. cursor = searchConnect.cursor()
  36. searched = cursor.execute('SELECT email,password FROM tblUsers WHERE email=(?) AND password=(?) ',(email,password,)).fetchall()
  37. result = False
  38. if searched == []:
  39. result = False
  40. else:
  41. result = True
  42. return result
  43.  
  44.  
  45. ### TKinter ###
  46.  
  47. class main(Frame):
  48. def __init__(self,master):
  49. super().__init__(master)
  50. self.grid()
  51. self.createwidgets()
  52.  
  53. def createwidgets(self):
  54. self.container = Frame(self, width = 1024,height=768)
  55. self.container.grid(row=0, column=0, sticky=W+E)
  56. self.frames = {}
  57. for f in (loginMenu, loginPage, homePage, storePage, galleryPage, FAQSPage, CreateLoginPage): # defined subclasses of BaseFrame
  58. frame = f(self.container,self)
  59. frame.grid(row=2, column=2, sticky=NW+SE)
  60. self.frames[f] = frame
  61. self.show_frame(loginMenu)
  62.  
  63. def show_frame(self, cls):
  64. """Show the specified frame.
  65.  
  66. Args:
  67. cls (tk.Frame): The class of the frame to show.
  68.  
  69. """
  70. self.frames[cls].tkraise()
  71.  
  72.  
  73. class loginMenu(Frame):
  74. ### A GUI application with three buttons. ###
  75.  
  76. def __init__(self,master,owner):
  77. ### Initialise the frame ###
  78. super().__init__(master)
  79. self.configure(background = "#496825")
  80. self.grid()
  81. self.owner = owner
  82. self.create_widgets()
  83.  
  84.  
  85. def create_widgets(self):
  86.  
  87.  
  88. ### Create three buttons that do nothing ###
  89. self.bttn1 = Button(self, text="Login", command = lambda: self.owner.show_frame(loginPage),width=15, height=4)
  90. self.bttn1.configure(background = "#E1E1E1")
  91. self.bttn1.grid(row=0)
  92.  
  93. self.bttn2 = Button(self, text="Create Login", command = lambda: self.owner.show_frame(CreateLoginPage),width=15, height=4)
  94. self.bttn2.configure(background = "#E1E1E1")
  95. self.bttn2.grid(row=3)
  96.  
  97. self.bttn3 = Button(self, text="Exit", width=15, height=4,command=self.byebye)
  98. self.bttn3.configure(background = "#E1E1E1")
  99. self.bttn3.grid(row=5)
  100.  
  101. ## [self.bttn3["text"] = "Same here! "] changes text
  102.  
  103. def byebye(self):
  104. self.owner.master.destroy()
  105.  
  106.  
  107. class CreateLoginPage(Frame):
  108.  
  109. def __init__(self,master,owner):
  110. super().__init__(master)
  111. self.configure(background = "#496825")
  112. self.grid()
  113. self.owner = owner
  114. self.create_widgets()
  115.  
  116. def create_widgets(self):
  117.  
  118. ### Creates the inputs for creating a user ###
  119. self.inst_lbl1 = Label(self, text = "First Name: ", fg="#FFFFFF", background = "#496825")
  120. self.inst_lbl2 = Label(self, text = "Last Name: ", fg="#FFFFFF", background = "#496825")
  121. self.inst_lbl3 = Label(self, text = "Email: ", fg="#FFFFFF", background = "#496825")
  122. self.inst_lbl4 = Label(self, text = "Phone Number: ", fg="#FFFFFF", background = "#496825")
  123. self.inst_lbl5 = Label(self, text = "Password: ", fg="#FFFFFF", background = "#496825")
  124. self.inst_lbl1.grid(row = 0, column = 0, columnspan = 2, sticky = W)
  125. self.inst_lbl2.grid(row = 1, column = 0, columnspan = 2, sticky = W)
  126. self.inst_lbl3.grid(row = 2, column = 0, columnspan = 2, sticky = W)
  127. self.inst_lbl4.grid(row = 3, column = 0, columnspan = 2, sticky = W)
  128. self.inst_lbl5.grid(row = 4, column = 0, columnspan = 2, sticky = W)
  129. # create entry widgets
  130. self.first_ent = Entry(self)
  131. self.last_ent = Entry(self)
  132. self.email_ent = Entry(self)
  133. self.phone_ent = Entry(self)
  134. self.password_ent = Entry(self, show="*")
  135. self.first_ent.grid(row = 0, column = 2, sticky = W)
  136. self.last_ent.grid(row = 1, column = 2, sticky = W)
  137. self.email_ent.grid(row = 2, column = 2, sticky = W)
  138. self.phone_ent.grid(row = 3, column = 2, sticky = W)
  139. self.password_ent.grid(row = 4, column = 2, sticky = W)
  140. # submit button
  141. self.submit_bttn = Button(self, text = "Submit", command = self.confirm)
  142. self.submit_bttn.configure(background = "#E1E1E1")
  143. self.submit_bttn.grid(row=5, column=0)
  144. self.back_bttn = Button(self, text = "Back", command = self.back)
  145. self.back_bttn.configure(background = "#E1E1E1")
  146. self.back_bttn.grid(row=5, column=1)
  147.  
  148. def back(self):
  149. self.owner.show_frame(loginMenu)
  150.  
  151. def confirm(self):
  152. firstContents = self.first_ent.get()
  153. self.first_ent.delete(0,END)
  154. lastContents = self.last_ent.get()
  155. self.last_ent.delete(0,END)
  156. emailContents = self.email_ent.get()
  157. self.email_ent.delete(0,END)
  158. phoneContents = self.phone_ent.get()
  159. self.phone_ent.delete(0,END)
  160. passwordContents = self.password_ent.get()
  161. self.password_ent.delete(0,END)
  162. passHash = hashlib.sha512(passwordContents.encode("UTF-8")).hexdigest()
  163. userConnect = sqlite3.connect("WoodActually.db")
  164. cursor = userConnect.cursor()
  165. userRec = []
  166. userRec.append(None)
  167. userRec.append(firstContents)
  168. userRec.append(lastContents)
  169. userRec.append(emailContents)
  170. userRec.append(phoneContents)
  171. userRec.append(passHash)
  172. cursor.execute("INSERT INTO tblUsers VALUES (?,?,?,?,?,?)", userRec)
  173. userConnect.commit()
  174. userRec = []
  175. userConnect.close()
  176. self.owner.show_frame(loginMenu)
  177.  
  178.  
  179. class loginPage(Frame):
  180.  
  181. def __init__(self,master,owner):
  182. super().__init__(master)
  183. self.configure(background = "#496825")
  184. self.grid()
  185. self.owner = owner
  186. self.create_widgets()
  187.  
  188. def create_widgets(self):
  189.  
  190. ### Creates the inputs for logging into the app ###
  191. self.inst_lbl1 = Label(self, text = "Email: ", fg="#FFFFFF", background = "#496825")
  192. self.inst_lbl2 = Label(self, text = "Password: ", fg="#FFFFFF", background = "#496825")
  193. self.inst_lbl1.grid(row = 0, column = 0, columnspan = 2, sticky = W)
  194. self.inst_lbl2.grid(row = 1, column = 0, columnspan = 2, sticky = W)
  195. # create entry widgets
  196. self.user_ent = Entry(self)
  197. self.pw_ent = Entry(self, show="*")
  198. self.user_ent.grid(row = 0, column = 2, sticky = W)
  199. self.pw_ent.grid(row = 1, column = 2, sticky = W)
  200. # create submit button
  201. self.submit_bttn = Button(self, text = "Submit", command = self.submit)
  202. self.submit_bttn.configure(background = "#E1E1E1")
  203. self.submit_bttn.grid(row=5)
  204. self.back_bttn = Button(self, text = "Back", command = self.back)
  205. self.back_bttn.configure(background = "#E1E1E1")
  206. self.back_bttn.grid(row=5, column=1)
  207.  
  208. def back(self):
  209. self.owner.show_frame(loginMenu)
  210.  
  211.  
  212. def submit(self):
  213. UserContents = self.user_ent.get()
  214. self.user_ent.delete(0,END)
  215. PwContents = self.pw_ent.get()
  216. passHash = hashlib.sha512(PwContents.encode("UTF-8")).hexdigest()
  217. self.pw_ent.delete(0,END)
  218. searchConnect = sqlite3.connect("WoodActually.db")
  219. cursor = searchConnect.cursor()
  220. searched = cursor.execute('SELECT email,password FROM tblUsers WHERE email=(?) AND password=(?) ',(UserContents,passHash)).fetchall()
  221. result = False
  222. if searched == []:
  223. result = False
  224.  
  225. self.owner.show_frame(loginMenu)
  226. else:
  227. result = True
  228. self.owner.show_frame(homePage)
  229.  
  230.  
  231.  
  232. class homePage(Frame):
  233.  
  234. def __init__(self,master,owner):
  235. super().__init__(master)
  236. self.configure(background = "#496825")
  237. self.grid()
  238. self.owner = owner
  239. self.create_widgets()
  240.  
  241. def create_widgets(self):
  242. self.bttn1 = Button(self, text="Store", command = lambda: self.owner.show_frame(storePage))
  243. self.bttn1.configure(background = "#E1E1E1")
  244. self.bttn1.grid(row=0, column = 0, columnspan=2, sticky=NSEW)
  245.  
  246. self.bttn2 = Button(self, text="Gallery", command = lambda: self.owner.show_frame(galleryPage))
  247. self.bttn2.configure(background = "#E1E1E1")
  248. self.bttn2.grid(row=0, column = 2, columnspan=2, sticky=NSEW)
  249.  
  250. self.bttn3 = Button(self, text="Home", command = lambda: self.owner.show_frame(homePage))
  251. self.bttn3.configure(background = "#E1E1E1")
  252. self.bttn3.grid(row=0, column = 4, columnspan=2, sticky=NSEW)
  253.  
  254. self.bttn4 = Button(self, text="FAQs", command = lambda: self.owner.show_frame(FAQSPage))
  255. self.bttn4.configure(background = "#E1E1E1")
  256. self.bttn4.grid(row=0, column = 6, columnspan=2, sticky=NSEW)
  257.  
  258. self.bttn5 = Button(self, text="Exit", command=self.byebye)
  259. self.bttn5.configure(background = "#E1E1E1")
  260. self.bttn5.grid(row=0, column = 8, columnspan=2, sticky=NSEW)
  261.  
  262. ############### TEXT ##################
  263.  
  264. 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")
  265. self.inst_lbl1.configure(background = "#496825")
  266. self.inst_lbl1.grid(row = 1, column = 0, columnspan = 10, sticky = W)
  267.  
  268.  
  269. def byebye(self):
  270. self.owner.master.destroy()
  271.  
  272. class storePage(Frame):
  273.  
  274. def __init__(self,master,owner):
  275. super().__init__(master)
  276. self.configure(background = "#496825")
  277. self.grid()
  278. self.owner = owner
  279. self.create_widgets()
  280.  
  281.  
  282. def create_widgets(self):
  283. self.bttn1 = Button(self, text="Store", command = lambda: self.owner.show_frame(storePage))
  284. self.bttn1.configure(background = "#E1E1E1")
  285. self.bttn1.grid(row=0, column = 0, columnspan=2, sticky=NSEW)
  286.  
  287. self.bttn2 = Button(self, text="Gallery", command = lambda: self.owner.show_frame(galleryPage))
  288. self.bttn2.configure(background = "#E1E1E1")
  289. self.bttn2.grid(row=0, column = 2, columnspan=2, sticky=NSEW)
  290.  
  291. self.bttn3 = Button(self, text="Home", command = lambda: self.owner.show_frame(homePage))
  292. self.bttn3.configure(background = "#E1E1E1")
  293. self.bttn3.grid(row=0, column = 4, columnspan=2, sticky=NSEW)
  294.  
  295. self.bttn4 = Button(self, text="FAQs", command = lambda: self.owner.show_frame(FAQSPage))
  296. self.bttn4.configure(background = "#E1E1E1")
  297. self.bttn4.grid(row=0, column = 6, columnspan=2, sticky=NSEW)
  298.  
  299. self.bttn5 = Button(self, text="Exit", command=self.byebye)
  300. self.bttn5.configure(background = "#E1E1E1")
  301. self.bttn5.grid(row=0, column = 8, columnspan=2, sticky=NSEW)
  302.  
  303. def byebye(self):
  304. self.owner.master.destroy()
  305.  
  306.  
  307. class galleryPage(Frame):
  308.  
  309. def __init__(self,master,owner):
  310. super().__init__(master)
  311. self.configure(background = "#496825")
  312. self.grid()
  313. self.owner = owner
  314. self.create_widgets()
  315.  
  316. def create_widgets(self):
  317. self.bttn1 = Button(self, text="Store", command = lambda: self.owner.show_frame(storePage))
  318. self.bttn1.configure(background = "#E1E1E1")
  319. self.bttn1.grid(row=0, column = 0, columnspan=2, sticky=NSEW)
  320.  
  321. self.bttn2 = Button(self, text= "Gallery", command = lambda: self.owner.show_frame(galleryPage))
  322. self.bttn2.configure(background = "#E1E1E1")
  323. self.bttn2.grid(row=0, column = 2, columnspan=2, sticky=NSEW)
  324.  
  325. self.bttn3 = Button(self, text="Home", command = lambda: self.owner.show_frame(homePage))
  326. self.bttn3.configure(background = "#E1E1E1")
  327. self.bttn3.grid(row=0, column = 4, columnspan=2, sticky=NSEW)
  328.  
  329. self.bttn4 = Button(self, text="FAQs", command = lambda: self.owner.show_frame(FAQSPage))
  330. self.bttn4.configure(background = "#E1E1E1")
  331. self.bttn4.grid(row=0, column = 6, columnspan=2, sticky=NSEW)
  332.  
  333. self.bttn5 = Button(self, text="Exit", command=self.byebye)
  334. self.bttn5.configure(background = "#E1E1E1")
  335. self.bttn5.grid(row=0, column = 8, columnspan=2, sticky=NSEW)
  336.  
  337. #####################################################
  338. path = "paw.gif"
  339.  
  340. self.img = PhotoImage(file = path)
  341.  
  342. panel = Label(self, image = self.img)
  343. panel.grid(row=1, column=0, columnspan=10)
  344.  
  345. #####################################################
  346.  
  347. pathSheep = "sheep.gif"
  348. self.Img2 = PhotoImage(file = pathSheep)
  349.  
  350. panel2 = Label(self, image = self.Img2)
  351. panel2.grid(row=1, column=1, columnspan=10)
  352. #####################################################
  353.  
  354. def byebye(self):
  355. self.owner.master.destroy()
  356.  
  357.  
  358. class FAQSPage(Frame):
  359.  
  360. def __init__(self,master,owner):
  361. super().__init__(master)
  362. self.configure(background = "#496825")
  363. self.grid()
  364. self.owner = owner
  365. self.create_widgets()
  366.  
  367. def create_widgets(self):
  368. self.bttn1 = Button(self, text="Store", command = lambda: self.owner.show_frame(storePage))
  369. self.bttn1.configure(background = "#E1E1E1")
  370. self.bttn1.grid(row=0, column = 0, columnspan=2, sticky=NSEW)
  371.  
  372. self.bttn2 = Button(self, text="Gallery", command = lambda: self.owner.show_frame(galleryPage))
  373. self.bttn2.configure(background = "#E1E1E1")
  374. self.bttn2.grid(row=0, column = 2, columnspan=2, sticky=NSEW)
  375.  
  376. self.bttn3 = Button(self, text="Home", command = lambda: self.owner.show_frame(homePage))
  377. self.bttn3.configure(background = "#E1E1E1")
  378. self.bttn3.grid(row=0, column = 4, columnspan=2, sticky=NSEW)
  379.  
  380. self.bttn4 = Button(self, text="FAQs", command = lambda: self.owner.show_frame(FAQSPage))
  381. self.bttn4.configure(background = "#E1E1E1")
  382. self.bttn4.grid(row=0, column = 6, columnspan=2, sticky=NSEW)
  383.  
  384. self.bttn5 = Button(self, text="Exit", command=self.byebye)
  385. self.bttn5.configure(background = "#E1E1E1")
  386. self.bttn5.grid(row=0, column = 8, columnspan=2, sticky=NSEW)
  387.  
  388. ################ TEXT ################
  389.  
  390. self.inst_lbl1 = Label(self, text = "Bears.", fg="#FFFFFF")
  391. self.inst_lbl1.configure(background = "#496825")
  392. self.inst_lbl1.grid(row = 1, column = 0, columnspan = 10, sticky = W)
  393.  
  394.  
  395.  
  396.  
  397. def byebye(self):
  398. self.owner.master.destroy()
  399.  
  400.  
  401.  
  402.  
  403. ##### MAIN #####
  404.  
  405. root = Tk()
  406. root.title("Wood Actually")
  407. root.geometry("1024x768")
  408. root.resizable(False,False)
  409. root.configure(background = "#496825")
  410.  
  411. # #496825 #GREEN
  412. # #E1E1E1 #Whitish?
  413.  
  414. app = main(root)
  415.  
  416. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement