I'm running into a tkinter situation that I cannot find a resolution for as of yet. I've got three database linked comboboxes that I would like to cascade. I've got them working somewhat, as in they populate correctly on bootup with the default selections, and the next combobox down the line is filtered down to what is appropriate from the preceding combobox selection. However, when I manually go and change a combo box, it does not cascade/update the other boxes, and always shows the choices from the top level selection.
All the examples I can find online are trivial and do not talk to databases.
I am not using the "trace" feature to track changes to fields, as it didn't give me enough control, and was also painting me into a corner. I'm relying on the "bind" function to try to make things cascade and to track field changes.
Here is the code where I define the first combobox:
All the examples I can find online are trivial and do not talk to databases.
I am not using the "trace" feature to track changes to fields, as it didn't give me enough control, and was also painting me into a corner. I'm relying on the "bind" function to try to make things cascade and to track field changes.
Here is the code where I define the first combobox:
keyMainTask=tk.StringVar() mydict, data = getCboList() frm = tk.Frame(taskframe, bg="cyan").place(x=col2-5, y=y1-5, width=width1+10, height=hgt1+10) cboTask = ttk.Combobox(taskframe, textvariable=keyMainTask, values=data) cboTask.place(x=col2, y=y1, width = width1, height=hgt1) cboTask.current(0) cboTask.bind('<<ComboboxSelected>>', updateMainTasks)Here is the code where I'm trying to make the cascading happen. First function is for the toplevel combobox, next function is for the next lower down combobox, which is trying to read the first combobox to know how to filter. It does filter, but I'm still only getting choices from the default value of the top level box:
def getCboList(): cnxn= sqlite3.connect(sqlFileLoc) c=cnxn.cursor() c.execute('Select Headline, TaskID from MainTasks') cnxn.commit() mydict=dict(c.fetchall()) data = list(mydict.keys()) c.close() cnxn.close() return mydict, data #================================================================================ def getCboListTaskSteps(): global mydict cnxn2= sqlite3.connect(sqlFileLoc) c2=cnxn2.cursor() try: #print(mydict[keyTaskStep.get()]) c2.execute('Select StepDescription, TaskStepID from TaskSteps where TaskID =' + str(mydict[cboTask.get()])) except: c2.execute('Select StepDescription, TaskStepID from TaskSteps ' ) cnxn2.commit() mydict2=dict(c2.fetchall()) #print(mydict2) data2 = list(mydict2.keys()) #print(data2) c2.close() cnxn2.close() return mydict2, data2And here is the beginning/subset of the code that is called by the "bind" function on the toplevel combobox. This code is where I try to update the fields on the form with data from the current combobox selection.
def updateMainTasks(self): cnxn= sqlite3.connect(sqlFileLoc) #try is to catch that mydict-key.get value exception when it is null try: sql='Select TaskID, Headline, Requester, Headline, Explanation,RequestDate, \ Complete, Acknowledged,DueDate from MainTasks \ where TaskID =' + str(mydict[cboTask.get()]) df=pd.read_sql_query(sql, cnxn) #Requester Requester1.delete(0,'end') try: Requester1.insert(0,df.iat[0,2]) except: print(df.iat[0,2])I have looked and looked online and in the forums, and as of yet have not hit the jackpot. Any help appreciated. Hopefully I've supplied enough code. The last assistance I received here helped immensely to get me out of a corner I was painted into. Thanks.