Advertisement
SinfulCross

Error tk

Jan 22nd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.99 KB | None | 0 0
  1. import pymysql
  2. import tkinter as tk                # python 3
  3. from tkinter import font as tkfont # python 3
  4. #import Tkinter as tk     # python 2
  5. #import tkFont as tkfont  # python 2
  6.  
  7.  
  8. class SampleApp(tk.Tk):
  9.  
  10.     def __init__(self, *args, **kwargs):
  11.         tk.Tk.__init__(self, *args, **kwargs)
  12.  
  13.         self.title_font = tkfont.Font(family='Helvetica', size=18, weight="bold", slant="italic")
  14.  
  15.         # the container is where we'll stack a bunch of frames
  16.         # on top of each other, then the one we want visible
  17.         # will be raised above the others
  18.         container = tk.Frame(self)
  19.         container.pack(side="top", fill="both", expand=True)
  20.         container.grid_rowconfigure(0, weight=1)
  21.         container.grid_columnconfigure(0, weight=1)
  22.  
  23.         self.frames = {}
  24.         for F in (StartPage, PageOne):
  25.             page_name = F.__name__
  26.             frame = F(parent=container, controller=self)
  27.             self.frames[page_name] = frame
  28.  
  29.             # put all of the pages in the same location;
  30.             # the one on the top of the stacking order
  31.             # will be the one that is visible.
  32.             frame.grid(row=0, column=0, sticky="nsew")
  33.  
  34.         self.show_frame("StartPage")
  35.  
  36.     def show_frame(self, page_name):
  37.         '''Show a frame for the given page name'''
  38.         frame = self.frames[page_name]
  39.         frame.tkraise()
  40.  
  41.         menu_bar = frame.menubar(self)
  42.         self.configure(menu=menu_bar)
  43.  
  44.  
  45. class StartPage(tk.Frame):
  46.  
  47.     def __init__(self, parent, controller):
  48.         tk.Frame.__init__(self, parent)
  49.         self.controller = controller
  50.         self.label_1 = tk.Label(parent, text="Username:")
  51.         self.label_2 = tk.Label(parent, text="Password:")
  52.         self.username = tk.Entry(parent, textvariable=tk.StringVar())
  53.         self.username.focus_set()
  54.         self.password = tk.Entry(parent, show="*", textvariable=tk.StringVar())
  55.         self.sign_in = tk.Button(parent, text="Sign In", command=self.validation)
  56.         self.label_1.grid(row=0)
  57.         self.label_2.grid(row=1)
  58.         self.username.grid(row=0, column=1, padx=3, pady=2)
  59.         self.password.grid(row=1, column=1)
  60.         self.sign_in.grid(row=2, column=1, rowspan=2)
  61.  
  62.     def validation(self, controller):
  63.         u = str(self.username.get())
  64.         p = str(self.password.get())
  65.         conn = pymysql.connect(host="localhost", user="root", password="", db="e-library")
  66.         c = conn.cursor()
  67.         verify_user = "SELECT * from tblusers WHERE username = %s AND password = %s"
  68.         c.execute(verify_user, (u, p))
  69.         results = c.fetchall()
  70.  
  71.         if results:
  72.             for i in results:
  73.                 print("Welcome " + i[1])
  74.         else:
  75.             print("Username or Password not recognized")
  76.  
  77.  
  78. class PageOne(tk.Frame):
  79.  
  80.     def __init__(self, parent, controller):
  81.         self.controller = controller
  82.         self.parent = parent
  83.  
  84.     def menu_bar(self, root):
  85.         main_menu = tk.Menu(root)
  86.         file_menu = tk.Menu(main_menu)
  87.         new_menu = tk.Menu(file_menu)
  88.         main_menu.add_cascade(label='File', menu=file_menu)
  89.         file_menu.add_cascade(label='New', menu=new_menu)
  90.         file_menu.add_command(label='Register Student...', command=self.new_student)
  91.         file_menu.add_command(label='Register Journal', menu=self.new_journal)
  92.         return main_menu
  93.  
  94.     def new_student(self):
  95.         print('I am a student')
  96.  
  97.     def new_journal(self):
  98.         print('I am a journal')
  99.  
  100. '''
  101. class PageTwo(tk.Frame):
  102.  
  103.    def __init__(self, parent, controller):
  104.        tk.Frame.__init__(self, parent)
  105.        self.controller = controller
  106.        label = tk.Label(self, text="This is page 2", font=controller.title_font)
  107.        label.pack(side="top", fill="x", pady=10)
  108.        button = tk.Button(self, text="Go to the start page",
  109.                           command=lambda: controller.show_frame("StartPage"))
  110.        button.pack()
  111. '''
  112.  
  113. if __name__ == "__main__":
  114.     app = SampleApp()
  115.     app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement