多选列表框用于在表中创建记录

时间:2014-04-01 15:33:14

标签: python sqlite listbox tkinter

我希望能够从列表框中选择用户选择的PatientID并在另一个表中使用它。 到目前为止,这是我的代码:

        window=Tk()
        listbox= Listbox(window, width='40', selectmode=EXTENDED)
        window.title('Please choose patients')
        Label(window,text='Please choose the patients to send job to:').grid(row=0, column=0)

        new_db=sqlite3.connect('H:\\patients.db')
        c=new_db.cursor()
        cursor=c.execute("SELECT Patient_id, Patient_forename, Patient_surname FROM PatientsTable")

        for row, row in enumerate(cursor):
            listbox.insert(END, row)

        listbox.grid(row=3, column=0)

        def Availability():
                selection=listbox.get(listbox.curselection())
                PatientsID=selection[0]
                new_db.execute('''INSERT INTO AvailablePatients (Patient_id,Surgery_id,Availablity_response)VALUES(?,?,' ')''',(PatientsID, JobIDValue,))
                new_db.commit()                            
                new_db.close

此代码适用于列表框中的一个选项,但我需要能够选择多个选项并为每个选择创建一个记录。我已尝试使用for和while循环并查找有关堆栈溢出的问题,但无法使其工作。谢谢你的帮助!

0 个答案:

没有答案
相关问题