Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.85 KB | None | 0 0
  1. def simpleMode():
  2.         list = [] # used to store all the variables that are created, this will be a 2d array
  3.         simpleButton.grid_forget()
  4.         advancedButton.grid_forget()
  5.  
  6.         # This function builds the SQL statement based on what the user ticked in checkboxes
  7.         def getInput():
  8.             SQL = "" # this will be the sql statement
  9.             for obj in list: # for every array in the 2d array 'list'
  10.                 a = obj[0] # will get the IntVar() object from the array
  11.                 if a.get() == 1: # if IntVar() is equal to 1, meaning if the checkbox was checked
  12.                     SQL = SQL + obj[1].replace(' ', '') + "," #adds the field to the sql statement to search for
  13.  
  14.             SQL = SQL[:-1] # this will remove the last character in the string, (comma)
  15.             SQL = SQL + " FROM " + tableOption # this is to tell what table we should get these fields from
  16.  
  17.             getSQLResult(SQL) #calls the getSQLResult function
  18.  
  19.         def getTable():
  20.             def createList(fields):
  21.                 for v in range(len(fields)):
  22.                     tempL = [] # sets 'tempL' array as empty
  23.                     tempL.append(IntVar()) # adds the object IntVar() to 'tempL'
  24.                     tempL.append(fields[v]) # adds the field name to the array
  25.                     checkboxObject = Checkbutton(inputCanvas, text = fields[v], variable = tempL[0]) # creates a checkbox object, with its name being the field name
  26.                     checkboxObject.grid(row = v+1, column = 0, sticky = W) # puts this on the canvas
  27.                     tempL.append(checkboxObject) # adds this checkbox object to the 'tempL' array
  28.  
  29.                     list.append(tempL) # adds this array to the 'list' array made at the beginning of this function
  30.  
  31.             global tableOption
  32.             tableOption = selectTable.get()
  33.  
  34.             for widget in inputCanvas.winfo_children():
  35.                 widget.destroy()
  36.  
  37.             Label(inputCanvas, text = "Enter the fields you want to get").grid(row = 0, column = 0, sticky = W)
  38.  
  39.             if tableOption == "Students":
  40.                 createList(studentFields)
  41.             if tableOption == "Courses":
  42.                 createList(courseFields)
  43.             if tableOption == "Info":
  44.                 createList(intersectFields)
  45.  
  46.             Button(inputCanvas, text = "Search", command = getInput).grid(row = 0, column = 1, sticky = W)
  47.  
  48.         Label(inputCanvas, text = "Which table would you like to get data from?").grid(row = 0, column = 0, sticky = W)
  49.         selectTable = ttk.Combobox(inputCanvas, values = ["Students", "Courses", "Info"], state = "readonly")
  50.         selectTable.grid(row = 0, column = 1, sticky = W)
  51.  
  52.         Button(inputCanvas, text = "Next", command = getTable).grid(row = 0, column = 2, sticky = W)
  53.  
  54.         inputCanvas.grid(row = 0, column = 0, sticky = W)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement