您好我已经创建了一个数据库,并使用了一个可以在python上运行的查询。现在我正在尝试为该程序创建一个GUI。查询取决于用户输入,到目前为止我设法创建菜单屏幕和输入屏幕但不确定如何将查询结果导入GUI屏幕。我也没有用过类来做这件事。请任何人帮忙吗?
以下是代码和搜索的示例;
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()
答案 0 :(得分:0)
这会在根窗口中创建一个新标签
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()
您无需创建课程。如果它不起作用则报告。