Feb-01-2021, 10:41 PM
Looks like there are multiple problems. The first problem is that you don't update the cboAddr combo box when you make a selection from the cboCust combo box. You execute this code once when work.__init()__ is called.
I would forget about returning the list of options and instead set the combo options inside the callback
self.cboCust['values'] = (fill_custbox())
self.cboCust.bind('<<ComboboxSelected>>', fill_addrbox)
self.cboAddr['values'] = (fill_addrbox()) # Only time ever called. Why the extra parenthesis?However there is no code that sets cboAddr['values'] ever again. You may call fill_addrbox(), but the values are never used.I would forget about returning the list of options and instead set the combo options inside the callback
def fill_custbox(*args): # THIS WORKS
print('Enter fill_custbox()', args) # <- For debugging purposes
conn = sqlite3.connect("service.db")
cur = conn.cursor()
cur.execute("SELECT DISTINCT cust FROM ticket Order BY cust")
data = []
for row in cur.fetchall():
print(row[0])
data.append(row[0])
# return data
self.cboCust['values'] = data
conn.commit() # <- These were never called. was that an error?
conn.close()
def fill_addrbox(*args): # THIS DOES NOT WORK
print('Enter fill_addrbox()', args) # <- For debugging purposes
conn = sqlite3.connect("service.db")
cur = conn.cursor()
cur.execute("SELECT distinct addr FROM ticket WHERE cust = '%s'" % (self.cboCust.get(),))
self.cboAddr.delete(0, END)
data = []
for row in cur.fetchall():
data.append(row[0])
print(row[0]) #<- If you add
# return data
self.cboAddr['values'] = data
conn.commit() # <- Once again, these never get called. Error?
conn.close()Now that code I mentioned at the top is changed to this:self.cboCust.bind('<<ComboboxSelected>>', fill_addrbox)
fill_addrbox()
