daily pastebin goal
46%
SHARE
TWEET

ok now were cooking

a guest Dec 9th, 2018 129 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import tkinter as tk     #importd tkinter and renames it as tk
  2. import sqlite3
  3. import re
  4. conn = sqlite3.connect('OS_Employee.db')
  5. LARGE_FONT= ("Verdana", 12)
  6.  
  7.  
  8. class Gui(tk.Tk):   #creat Gui class and inherit attributes of tk.TK
  9.  
  10.     def __init__(self, *args, **kwargs):    # the init methodology is going to initialize with the class right away this allows us to pass arguments and keyword arguments
  11.  
  12.         tk.Tk.__init__(self, *args, **kwargs)  #initialize tk within the initialization function
  13.         container = tk.Frame(self)             # defines the container to be filled with a bunch of frames to be used later
  14.         container.pack(side="top", fill="both", expand = True)    # configure general display
  15.         container.grid_rowconfigure(0, weight=1)
  16.         container.grid_columnconfigure(0, weight=1)
  17.  
  18.         self.frames = {}         #pre defined dictionary
  19.         for F in (HomePage, LoginPage, RegistrationPage, Deliverable1, Display):
  20.             frame = F(container, self)
  21.             self.frames[F] = frame
  22.             frame.grid(row=0, column=0, sticky="nsew")  #using grid to place the widget
  23.         self.show_frame(HomePage)    #call show_frame to bring the frame we want
  24.  
  25.     def show_frame(self, cont):
  26.  
  27.         frame = self.frames[cont]
  28.         frame.tkraise()          # this will bring our frame to the top for the user to see
  29.  
  30.  
  31. class HomePage(tk.Frame):
  32.  
  33.     def __init__(self, parent,controller):  #homepage
  34.         tk.Frame.__init__(self,parent)
  35.         self.configure(background="light grey")
  36.         label = tk.Label(self, text="Buisness Solution", font=LARGE_FONT, bg="light grey").pack()
  37.         label1 = tk.Label(self, text="online office supply retailer that ships furniture, tech, pens,\n files, etc. to consumers and corperations nation wide.", font=LARGE_FONT, bg="light grey",bd=1,relief="solid")
  38.         label1.pack(pady=10,padx=10)
  39.         button = tk.Button(self, text="Login", bg="#70ad47", fg="white",
  40.                             command=lambda: controller.show_frame(LoginPage))
  41.         button.pack()
  42.  
  43.         button2 = tk.Button(self, text="New User?", bg="#70ad47", fg="white",
  44.                             command=lambda: controller.show_frame(RegistrationPage))
  45.         button2.pack(pady=10)
  46.  
  47.  
  48. class LoginPage(tk.Frame):
  49.  
  50.     def __init__(self, parent, controller):  #LoginPage
  51.         tk.Frame.__init__(self, parent)
  52.         self.controller = controller
  53.         self.configure(background="light grey")
  54.         LPlabel0 = tk.Label(self, text="Enter Email and Password", font=LARGE_FONT, bg="light grey").grid(row=0,column=0)
  55.         LPlabel1 = tk.Label(self, text="Email:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=1,column=0)
  56.         LPlabel2 = tk.Label(self, text="Password:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=2,column=0)
  57.         self.username = tk.Entry(self)
  58.         self.username.grid(row=1,column=1)
  59.         self.password = tk.Entry(self)
  60.         self.password.grid(row=2,column=1)
  61.         self.status = tk.Label(self, fg='red', bg="light grey")
  62.         self.status.grid(row=0,column=1)
  63.         button1 = tk.Button(self, text="Back", bg="dark gray", fg="white",
  64.                             command=self.back)
  65.         button1.grid(sticky="W",row=3,column=1,pady=4)
  66.  
  67.         button2 = tk.Button(self, text="Continue", bg="#70ad47", fg="white",   #continue should go to diliverables
  68.                             command=self.login)    #command=lambda: controller.show_frame(Deliverable1))
  69.         button2.grid(sticky="E",row=3,column=1)
  70.  
  71.     def back(self):
  72.         self.username.delete(0, 'end')
  73.         self.password.delete(0, 'end')
  74.         self.status.config(text="")
  75.         self.controller.show_frame(HomePage)
  76.     def login(self):
  77.         with conn:
  78.             cur = conn.cursor()
  79.             try:
  80.                 # loginTest = False  # main condition to loop if email and password not met
  81.                 # while not loginTest:  # wrong email loopy
  82.                 userEmail = self.username.get()
  83.                 userEmail = userEmail.lower().replace(" ", "")
  84.                 userPassword = self.password.get()
  85.                 print("Username: {}, password: {}".format(userEmail, userPassword))
  86.                 cur.execute(
  87.                     "SELECT COUNT (*) FROM Employee WHERE(Email= '" + userEmail.lower() + "' AND Password= '" + userPassword + "')")
  88.                 results = cur.fetchone()  # return very first thing it finds that matches
  89.                 print(results[0])  # print first thing
  90.                 if results[0] == 1:
  91.                     print("Login successful")
  92.                     loginTest = True
  93.                     self.username.delete(0, 'end')
  94.                     self.password.delete(0, 'end')
  95.                     self.controller.show_frame(Deliverable1)
  96.                 else:
  97.                     print("Login Unsuccessful")
  98.                     self.status.config(text="wrong password or user name")
  99.                     self.username.delete(0, 'end')
  100.                     self.password.delete(0, 'end')
  101.                     self.controller.show_frame(LoginPage)
  102.  
  103.             except Exception as e:
  104.                 print(e)
  105.                 self.status.config(text="connection failed")
  106.  
  107.  
  108. class RegistrationPage(tk.Frame):  #registrationpage
  109.  
  110.     def __init__(self, parent, controller):
  111.         self.controller = controller
  112.         tk.Frame.__init__(self, parent)
  113.         self.configure(background="light grey")
  114.         label = tk.Label(self, text="Complete the fields below", font=LARGE_FONT, bg="light grey").grid(row=0,column=0)
  115.         label1 = tk.Label(self, text="First Name:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=1,column=0)
  116.         label11 = tk.Label(self, text="Last Name:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=2,column=0)
  117.         label2 = tk.Label(self, text="Employee ID:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=3,column=0)
  118.         label3 = tk.Label(self, text="E-mail:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=4,column=0)
  119.         label5 = tk.Label(self, text="Password:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=5,column=0)
  120.         # label6 = tk.Label(self, text="Confirm PW:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=6,column=0)
  121.         self.firstname = tk.Entry(self)
  122.         self.firstname.grid(row=1,column=1)
  123.         self.lastname = tk.Entry(self)
  124.         self.lastname.grid(row=2,column=1)
  125.         self.id = tk.Entry(self)
  126.         self.id.grid(row=3,column=1)
  127.         self.email = tk.Entry(self)
  128.         self.email.grid(row=4,column=1)
  129.         self.password = tk.Entry(self)
  130.         self.password.grid(row=5,column=1)
  131.         self.status = tk.Label(self, fg='red', bg="light grey")
  132.         self.status.grid(row=0,column=1)
  133.         # self.confirm_pass = tk.Entry(self)
  134.         # self.confirm_pass.grid(row=6,column=1)
  135.  
  136.         button1 = tk.Button(self, text="Back", bg="dark gray", fg="white",
  137.                             command=self.back)
  138.         button1.grid(sticky="w",row=6,column=1,pady=4)
  139.  
  140.         button2 = tk.Button(self, text="Continue", bg="#70ad47", fg="white",
  141.                             command=self.register)    # command=lambda: controller.show_frame(LoginPage))
  142.         button2.grid(sticky="E",row=6,column=1)
  143.  
  144.     def back(self):
  145.         self.firstname.delete(0, "end")
  146.         self.lastname.delete(0, "end")
  147.         self.password.delete(0, "end")
  148.         self.email.delete(0, "end")
  149.         self.id.delete(0, "end")
  150.         self.controller.show_frame(HomePage)
  151.     def register(self):
  152.         with conn:
  153.             cur = conn.cursor()
  154.             try:
  155.                 if self.id.get():
  156.                     EmployeeID = int(self.id.get())
  157.  
  158.                 FirstName = self.firstname.get()
  159.                 # while FirstName == "":
  160.                 #     FirstName = self.firstname.get()
  161.                 #     FirstName = FirstName.title()
  162.  
  163.                 LastName = self.lastname.get()
  164.                 # while LastName == "":
  165.                 #     LastName = self.lastname.get()
  166.                 #     LastName = LastName.title()
  167.  
  168.                 Email = self.email.get().lower()
  169.                 match = re.match('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$', Email)
  170.                 if match is None:
  171.                     print('Bad Syntax')
  172.                     #raise ValueError('Bad Syntax')
  173.  
  174.                 Password = self.password.get()
  175.                 Password = Password.lower()
  176.  
  177.                 cur.execute(
  178.                     'insert into employee values(?,?,?,?,?)',
  179.                     (EmployeeID, FirstName, LastName, Email, Password))
  180.                 cur.execute(
  181.                     'select * from employee where EmployeeId=?',
  182.                     (EmployeeID,))
  183.  
  184.                 results = cur.fetchall()
  185.                 print(results)
  186.                 self.firstname.delete(0, "end")
  187.                 self.lastname.delete(0, "end")
  188.                 self.password.delete(0, "end")
  189.                 self.email.delete(0, "end")
  190.                 self.id.delete(0, "end")
  191.                 self.controller.show_frame(Deliverable1)
  192.             except sqlite3.Error as e:
  193.                 print(e)
  194.                 print("User already exist")
  195.                 self.status.config(text="wrong password")
  196.  
  197. class Deliverable1(tk.Frame):  #registrationpage
  198.  
  199.     def __init__(self, parent, controller):
  200.         tk.Frame.__init__(self, parent)
  201.         self.controller = controller
  202.         self.configure(background="light grey")
  203.         label = tk.Label(self, text="Select what to display", font=LARGE_FONT, bg="light grey").grid(row=0,column=0)
  204.         label1 = tk.Label(self, text="10 Most Profitable:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=1,column=0)
  205.         label2 = tk.Label(self, text="10 least profitable:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=2,column=0)
  206.         label3 = tk.Label(self, text="Which State:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=3,column=0)
  207.         label5 = tk.Label(self, text="Which Product:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=4,column=0)
  208.         label6 = tk.Label(self, text="Year:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=5,column=0)
  209.         label7 = tk.Label(self, text="Month:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=6,column=0)
  210.         label8 = tk.Label(self, text="Quarter:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=7,column=0)
  211.         entry1 = tk.Entry(self).grid(sticky="W",row=6,column=1)
  212.         entry2 = tk.Entry(self).grid(sticky="W",row=7,column=1)
  213.         self.status = tk.Label(self, fg='red', bg="light grey")
  214.         self.status.grid(row=0,column=1)
  215.  
  216.         v = tk.IntVar()
  217.         tk.Radiobutton(self, variable=v, value=1, bg="light grey").grid(sticky="W",row=2,column=1)
  218.         tk.Radiobutton(self, variable=v, value=2, bg="light grey").grid(sticky="W",row=1,column=1)
  219.  
  220.         button1 = tk.Button(self, text="Log Out", bg="red", fg="white",     #make the back button a logout button?
  221.                             command=self.logout)    #command=lambda: controller.show_frame(HomePage))
  222.         button1.grid(sticky="w",row=8,column=1,pady=5)
  223.  
  224.         button2 = tk.Button(self, text="Continue", bg="#70ad47", fg="white",    #go to displayproducts in order
  225.                             command=lambda: controller.show_frame(Display))
  226.         button2.grid(sticky="E",row=8,column=1)
  227.  
  228.         self.state = tk.Entry(self)
  229.         self.state.grid(sticky="W",row=3,column=1)
  230.  
  231.         self.product = tk.Entry(self)
  232.         self.product.grid(sticky="W",row=4,column=1)
  233.  
  234.         self.year = tk.Entry(self)
  235.         self.year.grid(sticky="W",row=5,column=1)
  236.  
  237.     def logout(self):
  238.         self.status.config(text="")
  239.         self.controller.show_frame(HomePage)
  240.  
  241.  
  242.  
  243. class Display(tk.Frame):
  244.  
  245.     def __init__(self, parent, controller):  #homepage
  246.         tk.Frame.__init__(self,parent)
  247.         self.configure(background="light grey")
  248.         label = tk.Label(self, text="Profitable products", font=LARGE_FONT, bg="light grey").pack(pady=10)
  249.  
  250.         listbox = tk.Listbox(self).pack()
  251.  
  252.         #for i in range(20):
  253.          #listbox.insert(END, str(i))
  254.  
  255.         button = tk.Button(self, text="Back", bg="dark grey", fg="white",
  256.                             command=lambda: controller.show_frame(Deliverable1))
  257.         button.pack(pady=7)
  258.  
  259.  
  260. app = Gui()       #App is the object of the Gui class
  261. app.mainloop()    # then run .mainloop()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top