Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pyinstaller -w programname.py -F
- # Copy and Paste Buttons BEGIN Here
- def cut(self):
- self.clipboard_clear()
- self.clipboard_append(self.outline.focus_get().get())
- self.outline.focus_get().delete(0, END)
- def copy(self):
- self.clipboard_clear()
- self.clipboard_append(self.outline.focus_get().get())
- def paste(self):
- text = self.clipboard_get()
- self.outline.focus_get().insert(0, text)
- def delete(self):
- self.outline.focus_get().delete(0, END)
- def popup(self, event):
- event.widget.focus() # This moves the focus to the entry field you right click in.
- self.aMenu.post(event.x_root, event.y_root)
- # Copy and Paste Buttons END Here
- # For copy button
- self.aMenu = tk.Menu(self, tearoff=0)
- self.aMenu.add_command(label='Cut', command=self.cut)
- self.aMenu.add_command(label='Copy', command=self.copy)
- self.aMenu.add_command(label='Paste', command=self.paste)
- self.aMenu.add_command(label='Delete', command=self.delete)
- import os
- import pypyodbc
- from tkinter import BOTH, END, LEFT
- from tkinter import ttk
- import tkinter as tk
- class Adder(ttk.Frame):
- """The adders gui and functions."""
- def __init__(self, parent, *args, **kwargs):
- ttk.Frame.__init__(self, parent, *args, **kwargs)
- self.root = parent
- self.init_gui()
- # Copy and Paste Buttons BEGIN Here
- def cut(self):
- self.clipboard_clear()
- self.clipboard_append(self.outline.focus_get().get())
- self.outline.focus_get().delete(0, END)
- def copy(self):
- self.clipboard_clear()
- self.clipboard_append(self.outline.focus_get().get())
- def paste(self):
- text = self.clipboard_get()
- self.outline.focus_get().insert(0, text)
- def delete(self):
- self.outline.focus_get().delete(0, END)
- def popup(self, event):
- event.widget.focus() # This moves the focus to the entry field you right click in.
- self.aMenu.post(event.x_root, event.y_root)
- # Copy and Paste Buttons END Here
- def on_help(self):
- answer = messagebox.showinfo("Info will go here.")
- def on_quit(self):
- """Exits program."""
- root.quit()
- def authenticate(self):
- return pypyodbc.connect('Driver={SQL Server};Server=srv201;Database=IDPXIDp;Trusted_Connection=yes;')
- def calculate(self):
- firstname = str(self.first_entry.get())
- lastname = str(self.last_entry.get())
- license = str(self.lic_entry.get())
- if (firstname and not lastname and not license): # "You entered first name."
- try:
- connection = self.authenticate()
- except pypyodbc.Error as ex:
- sqlstate = ex.args[0]
- if sqlstate == '28000':
- self.output0.delete(0, END)
- self.output0.insert(0,"You do not have access.")
- cursor = connection.cursor()
- SQLCommand = ("SELECT LASTNAME, FIRSTNAME, L_LICNUMBER, E_ENAME "
- "FROM dbo.V_MYTABLE_IT " # table name
- "with (nolock)"
- "WHERE FIRSTNAME = ?")
- Values = [firstname]
- cursor.execute(SQLCommand,Values)
- results = cursor.fetchmany(10)
- if results:
- self.output0.delete(0, END)
- self.output0.insert(0,results[0])
- connection.close()
- else:
- self.output0.delete(0, END)
- self.output0.insert(0,"That name does not exist.")
- elif len(firstname) == 0 and len(license) == 0: # "You entered last name."
- try:
- connection = pypyodbc.connect('Driver={SQL Server};Server=srv201;Database=IDPXIDp;Trusted_Connection=yes;')
- except pypyodbc.Error as ex:
- sqlstate = ex.args[0]
- if sqlstate == '28000':
- self.output0.delete(0, END)
- self.output0.insert(0,"You do not have access.")
- cursor = connection.cursor()
- SQLCommand = ("SELECT LASTNAME, FIRSTNAME, L_LICNUMBER, E_ENAME "
- "FROM dbo.V_MYTABLE_IT " # table name
- "with (nolock)"
- "WHERE LASTNAME = ?")
- Values = [lastname]
- cursor.execute(SQLCommand,Values)
- results = cursor.fetchmany(10)
- if results:
- self.output0.delete(0, END)
- self.output0.insert(0,results[0])
- connection.close()
- else:
- self.output0.delete(0, END)
- self.output0.insert(0,"That name does not exist.")
- elif len(firstname) == 0 and len(lastname) == 0: # "You entered license."
- try:
- connection = pypyodbc.connect('Driver={SQL Server};Server=srv201;Database=IDPXIDp;Trusted_Connection=yes;')
- except pypyodbc.Error as ex:
- sqlstate = ex.args[0]
- if sqlstate == '28000':
- self.output0.delete(0, END)
- self.output0.insert(0,"You do not have access.")
- cursor = connection.cursor()
- SQLCommand = ("SELECT LASTNAME, FIRSTNAME, L_LICNUMBER, E_ENAME "
- "FROM dbo.V_MYTABLE_IT " # table name
- "with (nolock)"
- "WHERE L_LICNUMBER = ?")
- Values = [license]
- cursor.execute(SQLCommand,Values)
- results = cursor.fetchmany(10)
- if results:
- self.output0.delete(0, END)
- self.output0.insert(0,results[0])
- connection.close()
- else:
- self.output0.delete(0, END)
- self.output0.insert(0,"That license does not exist.")
- elif (not firstname and not lastname and not license): # "You entered first name."
- try:
- connection = self.authenticate()
- except pypyodbc.Error as ex:
- sqlstate = ex.args[0]
- if sqlstate == '28000':
- self.output0.delete(0, END)
- self.output0.insert(0,"You do not have access.")
- cursor = connection.cursor()
- SQLCommand = ("SELECT LASTNAME, FIRSTNAME, L_LICNUMBER, E_ENAME "
- "FROM dbo.V_MYTABLE_IT " # table name
- "with (nolock)"
- "WHERE FIRSTNAME = ?")
- Values = [firstname]
- cursor.execute(SQLCommand,Values)
- results = cursor.fetchmany(10)
- if results:
- self.output0.delete(0, END)
- self.output0.insert(0,"No data entered")
- connection.close()
- elif len(lastname) == 0: # "You entered first name and license."
- try:
- connection = pypyodbc.connect('Driver={SQL Server};Server=srv201;Database=IDPXIDp;Trusted_Connection=yes;')
- except pypyodbc.Error as ex:
- sqlstate = ex.args[0]
- if sqlstate == '28000':
- self.output0.delete(0, END)
- self.output0.insert(0,"You do not have access.")
- cursor = connection.cursor()
- SQLCommand = ("SELECT LASTNAME, FIRSTNAME, L_LICNUMBER, E_ENAME "
- "FROM dbo.V_MYTABLE_IT " # table name
- "with (nolock)"
- "WHERE FIRSTNAME = ? AND L_LICNUMBER = ?")
- Values = [firstname, license] # make a list for user inputs
- cursor.execute(SQLCommand,Values)
- results = cursor.fetchmany(10)
- if results:
- self.output0.delete(0, END)
- self.output0.insert(0,results[0])
- connection.close()
- else:
- self.output0.delete(0, END)
- self.output0['text'] = "That combination does not exist."
- elif len(firstname) == 0: # "You entered last name and license."
- try:
- connection = pypyodbc.connect('Driver={SQL Server};Server=srv201;Database=IDPXIDp;Trusted_Connection=yes;')
- except pypyodbc.Error as ex:
- sqlstate = ex.args[0]
- if sqlstate == '28000':
- self.output0.delete(0, END)
- self.output0.insert(0,"You do not have access.")
- cursor = connection.cursor()
- SQLCommand = ("SELECT LASTNAME, FIRSTNAME, L_LICNUMBER, E_ENAME "
- "FROM dbo.V_MYTABLE_IT " # table name
- "with (nolock)"
- "WHERE LASTNAME = ? AND L_LICNUMBER = ?")
- Values = [lastname, license]
- cursor.execute(SQLCommand,Values)
- results = cursor.fetchmany(10)
- if results:
- self.output0.delete(0, END)
- self.output0.insert(0,results[0])
- connection.close()
- else:
- self.output0.delete(0, END)
- self.output0.insert(0,"That combination does not exist.")
- elif len(license) == 0: # "You entered first name and last name."
- try:
- connection = pypyodbc.connect('Driver={SQL Server};Server=srv201;Database=IDPXIDp;Trusted_Connection=yes;')
- except pypyodbc.Error as ex:
- sqlstate = ex.args[0]
- if sqlstate == '28000':
- self.output0.delete(0, END)
- self.output0.insert(0,"You do not have access.")
- cursor = connection.cursor()
- SQLCommand = ("SELECT LASTNAME, FIRSTNAME, L_LICNUMBER, E_ENAME "
- "FROM dbo.V_MYTABLE_IT " # table name
- "with (nolock)"
- "WHERE FIRSTNAME = ? AND LASTNAME = ?")
- Values = [firstname, lastname]
- cursor.execute(SQLCommand,Values)
- results = cursor.fetchmany(10)
- if results:
- self.output0.delete(0, END)
- self.output0.insert(0,results[0])
- connection.close()
- else:
- self.output0.delete(0, END)
- self.output0.insert(0,"That combination does not exist.")
- else:
- firstname = str(self.first_entry.get())
- lastname = str(self.last_entry.get())
- license = str(self.lic_entry.get())
- try:
- connection = pypyodbc.connect('Driver={SQL Server};Server=srv201;Database=IDPXIDp;Trusted_Connection=yes;')
- except pypyodbc.Error as ex:
- sqlstate = ex.args[0]
- if sqlstate == '28000':
- self.answer_label['text'] = "You do not have access."
- cursor = connection.cursor()
- SQLCommand = ("SELECT TOP (10) LASTNAME, FIRSTNAME, L_LICNUMBER, E_ENAME "
- "FROM dbo.V_MYTABLE_IT " # table name
- "(nolock)"
- "WHERE FIRSTNAME = ? AND LASTNAME = ? AND L_LICNUMBER = ?")
- Values = [firstname, lastname, license]
- cursor.execute(SQLCommand,Values)
- results = cursor.fetchmany(10)
- if results:
- self.output0.delete(0, END)
- self.output0.insert(0,results[0])
- connection.close()
- else:
- self.output0.delete(0, END)
- self.output0.insert(0,"That combination does not exist.")
- def init_gui(self):
- """Builds GUI."""
- self.root.title('Verify')
- self.root.option_add('*tearOff', 'FALSE')
- self.grid(column=0, row=0, sticky='nsew') # this starts the entire form
- self.menubar = tk.Menu(self.root)
- self.menu_file = tk.Menu(self.menubar)
- self.menu_file.add_command(label='About', command=self.on_help)
- self.menu_file.add_command(label='Exit', command=self.on_quit)
- self.menu_edit = tk.Menu(self.menubar)
- self.menubar.add_cascade(menu=self.menu_file, label='File')
- # self.menubar.add_cascade(menu=self.menu_edit, label='Help') # add other menu options
- self.root.config(menu=self.menubar)
- self.outline = tk.LabelFrame(self, height=80, width=900) # border frame
- self.outline.grid(column=0, row=1, columnspan=5, padx=5, ipady=10, pady=5)
- # Text Labels
- self.labelframespace = tk.Frame(self, height=0, width=100) # provides spacing BEFORE labels
- self.labelframespace.grid(column=0, row=1, columnspan=1)
- self.first = tk.Label(self, text='FirstName:')
- self.first.grid(column=1, row=1, sticky='nw', padx=10, pady=20)
- self.last = ttk.Label(self, text='LastName:')
- self.last.grid(column=2, row=1, sticky='nw', padx=10, pady=20)
- self.lic = ttk.Label(self, text='License:')
- self.lic.grid(column=3, row=1, sticky='nw', padx=10, pady=20)
- self.labelframespace = tk.Frame(self, height=0, width=50) # provides spacing AFTER labels
- self.labelframespace.grid(column=4, row=1, columnspan=1)
- self.labelframespace = tk.Frame(self, height=0, width=200) # provides spacing AFTER labels
- self.labelframespace.grid(column=4, row=1, columnspan=1)
- # Input Boxes and Button
- self.first_entry = tk.Entry(self, width=28) # first input box
- self.first_entry.grid(sticky='', column=1, row=1)
- self.first_entry.bind("<Button-3>", self.popup)
- self.last_entry = tk.Entry(self, width=28) # second input box
- self.last_entry.grid(sticky='', column=2, row=1)
- self.last_entry.bind("<Button-3>", self.popup)
- self.lic_entry = tk.Entry(self, width=28) # third input box
- self.lic_entry.grid(sticky='', column=3, row=1)
- self.lic_entry.bind("<Button-3>", self.popup)
- self.framespace = tk.Frame(self, height=5, width=896, bg='#E0E0E0') # provides spacing between input boxes and answer box
- self.framespace.grid(row=4, columnspan=5)
- self.calc_button = ttk.Button(self, text='Search', command=self.calculate) # button
- self.calc_button.grid(column=4, row=1, columnspan=1, sticky='w', padx=14)
- self.calc_button.bind('<Return>', lambda e: self.calculate())
- # For copy button
- self.aMenu = tk.Menu(self, tearoff=0)
- self.aMenu.add_command(label='Cut', command=self.cut)
- self.aMenu.add_command(label='Copy', command=self.copy)
- self.aMenu.add_command(label='Paste', command=self.paste)
- self.aMenu.add_command(label='Delete', command=self.delete)
- # Output frame for answer
- self.entries = []
- self.output0 = tk.Entry(self, width=149, justify='center', bd='0', bg='#E0E0E0')
- self.output0.grid(column=0, row=6, columnspan=5, padx=1)
- self.output0.bind("<Button-3>", self.popup)
- self.entries.append(self.output0) # makes the answer not display multiple times on the same line
- self.blank = tk.LabelFrame(self, height=5, bd=0,) # blank line
- self.blank.grid(row=16,)
- if __name__ == '__main__':
- root = tk.Tk()
- Adder(root)
- root.resizable(width=False, height=False) # locks window from being resized
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement