Python Forum
Linking Comboboxes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Linking Comboboxes
#21
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.
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()
Reply


Messages In This Thread
Linking Comboboxes - by MrP - Jan-24-2021, 05:08 PM
RE: Linking Comboboxes - by Larz60+ - Jan-24-2021, 06:49 PM
RE: Linking Comboboxes - by MrP - Jan-24-2021, 07:32 PM
RE: Linking Comboboxes - by Larz60+ - Jan-24-2021, 09:31 PM
RE: Linking Comboboxes - by MrP - Jan-30-2021, 01:35 PM
RE: Linking Comboboxes - by deanhystad - Jan-31-2021, 04:09 AM
RE: Linking Comboboxes - by MrP - Jan-31-2021, 11:41 AM
RE: Linking Comboboxes - by deanhystad - Jan-31-2021, 02:14 PM
RE: Linking Comboboxes - by MrP - Jan-31-2021, 04:10 PM
RE: Linking Comboboxes - by deanhystad - Jan-31-2021, 04:34 PM
RE: Linking Comboboxes - by MrP - Jan-31-2021, 09:04 PM
RE: Linking Comboboxes - by MrP - Jan-31-2021, 09:41 PM
RE: Linking Comboboxes - by MrP - Jan-31-2021, 09:45 PM
RE: Linking Comboboxes - by MrP - Jan-31-2021, 06:37 PM
RE: Linking Comboboxes - by deanhystad - Jan-31-2021, 08:41 PM
RE: Linking Comboboxes - by deanhystad - Jan-31-2021, 09:33 PM
RE: Linking Comboboxes - by deanhystad - Jan-31-2021, 10:12 PM
RE: Linking Comboboxes - by MrP - Feb-01-2021, 12:06 PM
RE: Linking Comboboxes - by deanhystad - Feb-01-2021, 03:04 PM
RE: Linking Comboboxes - by MrP - Feb-01-2021, 09:39 PM
RE: Linking Comboboxes - by deanhystad - Feb-01-2021, 10:41 PM
RE: Linking Comboboxes - by MrP - Feb-02-2021, 12:29 AM
RE: Linking Comboboxes - by deanhystad - Feb-02-2021, 01:03 AM
RE: Linking Comboboxes - by Serafim - Feb-02-2021, 09:06 AM
RE: Linking Comboboxes - by MrP - Feb-03-2021, 10:59 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Can't get tkinter database aware cascading comboboxes to update properly dford 6 3,708 Jan-11-2022, 08:37 PM
Last Post: deanhystad
  Print Values from a Sequence of Entries / ComboBoxes MC2020 4 2,858 Mar-28-2020, 10:05 PM
Last Post: MC2020
  [PyQt] making dependant comboBoxes Hitsugaya 3 5,059 May-23-2019, 06:05 PM
Last Post: Alfalfa

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020