Question

Hi I have created a database and have used a query which all works on python. Now I am trying to create a GUI for the program. The query depends on a user input, I have so far managed to create a menu screen and the input screen but am unsure on how to get the results from the query into the GUI screen. Also I have not used a class to do this. Please can anyone help?

Here is an example of what the code and search looks like;

def Search():
    global E1, E2, E3, E4, file

    #Retaining user input
    Entry1 = E1.get()
    Entry2 = E2.get()
    Entry3 = E3.get()
    Entry4 = E4.get()

    #The search
    cursor = file.execute ('''SELECT patient_ID, forename, surname, DOB,from practicedatabase WHERE variable1 =? and variable2=? and variable3=? and variable4=?''', (Entry1, Entry2, Entry3, Entry4)) 

for row in cursor:
    print ("ID = ", row[0])
    print ("Forename = ", row[1])
    print ("Surname = ", row[2])
    print ("DOB = ", row[3])


print ("Search complete ");
file.close()
Was it helpful?

Solution

This creates a new label in the root window

root = Tk()

for row_number, row in enumerate(cursor):
    Label(root, text = "ID = " + str(row[0])).grid(column = 1, row = row_number)
    Label(root, text = "Forename = " + str(row[1])).grid(column = 2, row = row_number)
    print ("Surname = ", row[2]) # and so on. transform this too
    print ("DOB = ", row[3])

file.close()
root.mainloop()

You do not need to create a class. Report back if it does not work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top