Python Forum
Linking Comboboxes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Linking Comboboxes
#11
self.cboCust['values'] = (fill_custbox())
self.cboCust.bind('<<ComboboxSelected>>', fill_addrbox)
self.cboAddr['values'] = (fill_addrbox())
Exception in Tkinter callback
Traceback (most recent call last):
File "D:\Python 3.7.9\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
TypeError: fill_addrbox() takes 0 positional arguments but 1 was given

But if I put event in like this def fill_addrbox(event): I get this:
builtins.TypeError: fill_addrbox() missing 1 required positional argument: 'event'

and then if I put event here: self.cboAddr['values'] = (fill_addrbox(event)) I get: builtins.NameError: name 'event' is not defined
Reply
#12
The problem you are seeing is easy to fix.
def fill_addrbox(*args):
Problem solved. You could even do this to see what kind of value is sent and if it is useful for your purposes.
def fill_addrbox(*args):
    print(args)
I don't know if the query will work, or if it will return anything you can use to fill your combo box, but at least you can push buttons without crashing.

What I was asking for earlier was to just call the function and print what is returned. This is a useful debugging technique. When I write GUI code I never bind functions to buttons or events until I already know the function works. Once I know the code works any problems that occur after binding to the GUI are all binding problems.
Reply
#13
(Jan-31-2021, 04:34 PM)deanhystad Wrote: I am trying to determine if the problem is the query. If you execute this code what do you get? Does it return an empty list? If there are items in the list, what are the items? Are they tuples or lists?
def fill_addrbox():   # THIS DOES NOT WORK
              
    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])
        # self.cboAddr.insert('', row[0],)
        # print(row)
    return data
as it reads without binding it to an event I get no errors and a tuple is returned to the debug screen due to the print function in the 9th row and nothing is populated to the address combo text box
Reply
#14
Nothing should get added to the combo box since that line of code is commented out. Sounds like it works.
Reply
#15
(Jan-31-2021, 09:04 PM)MrP Wrote:
(Jan-31-2021, 04:34 PM)deanhystad Wrote: I am trying to determine if the problem is the query. If you execute this code what do you get? Does it return an empty list? If there are items in the list, what are the items? Are they tuples or lists?
def fill_addrbox():   # THIS DOES NOT WORK
              
    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])
        # self.cboAddr.insert('', row[0],)
        # print(row)
    return data
as it reads without binding it to an event I get no errors and a tuple is returned to the debug screen due to the print function in the 9th row and nothing is populated to the address combo text box
ok putting the *args in stopped a bunch of errors but it still is not populating the combo box!! the print function is printing the correct data to the debug screen. The functions for the fill_cust and fill_addr are identical with the exception that I'm trying to filter by the selection of the cust combobox, without the filter it will and does populate the addr combobox with all the addresses for all the customers. I don't know how to explain this any better, it JUST doesn't work when I use the WHERE statement.
Reply
#16
(Jan-31-2021, 09:04 PM)MrP Wrote:
(Jan-31-2021, 04:34 PM)deanhystad Wrote: I am trying to determine if the problem is the query. If you execute this code what do you get? Does it return an empty list? If there are items in the list, what are the items? Are they tuples or lists?
def fill_addrbox():   # THIS DOES NOT WORK
              
    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])
        # self.cboAddr.insert('', row[0],)
        # print(row)
    return data
as it reads without binding it to an event I get no errors and a tuple is returned to the debug screen due to the print function in the 9th row and nothing is populated to the address combo text box
ok putting the *args in stopped a bunch of errors but it still is not populating the combo box!! the print function is printing the correct data to the debug screen. The functions for the fill_cust and fill_addr are identical with the exception that I'm trying to filter by the selection of the cust combobox, without the filter it will and does populate the addr combobox with all the addresses for all the customers. I don't know how to explain this any better, it JUST doesn't work when I use the WHERE statement.
I have tried: cur.execute("SELECT distinct addr FROM ticket WHERE cust = '%s'" % (self.cboCust.get(),))
I have tried: cur.execute("SELECT distinct addr FROM ticket WHERE cust = ?" , (self.cboCust.get(),))
nothing seems to work
Reply
#17
Are you sure there is nothing in the combo box? Have you looked? I notice that you are not making any selection in your callback.
Reply
#18
(Jan-31-2021, 10:12 PM)deanhystad Wrote: Are you sure there is nothing in the combo box? Have you looked? I notice that you are not making any selection in your callback.

sorry for the delay and thankyou for your patience...if I try to fill the combo box from within the function it returns everything in one line, there are no separate selections but if I use the callback that is around line 210 of the original post nothing shows up in the combo box even though the print function is putting the separated items in the debug screen
Reply
#19
I think it would be very useful if you could post what it is you are seeing. I still don't know what the query is returning. Because I don't know what is returned it is difficult to say why it is not getting added to the combobox.
Reply
#20
(Feb-01-2021, 03:04 PM)deanhystad Wrote: I think it would be very useful if you could post what it is you are seeing. I still don't know what the query is returning. Because I don't know what is returned it is difficult to say why it is not getting added to the combobox.
Here you go...
cur.execute("SELECT distinct addr FROM ticket WHERE cust = ?" , (self.cboCust.get(),))
self.cboAddr.delete(0, END)
data = []
for row in cur.fetchall():
data.append(row[0])
>>>>>>> self.cboAddr.insert(END, (row))
print(row[0])
return data
conn.commit()
conn.close()
self.cboCust['values'] = (fill_custbox())
>>>>> #self.cboCust.bind('<<ComboboxSelected>>', fill_addrbox)
>>>>> #self.cboAddr['values'] = (fill_addrbox())
Combo Box: abababablklklk
Debug Window: abababab
lklklk

for row in cur.fetchall():
data.append(row[0])
>>>>> #self.cboAddr.insert(END, (row))
print(row[0])
return data

self.cboCust['values'] = (fill_custbox())
>>>>> self.cboCust.bind('<<ComboboxSelected>>', fill_addrbox)
>>>>> self.cboAddr['values'] = (fill_addrbox())
Combo Box: nothing, empty, nada
Debug Window: abababab
lklklk
abababab
lklklk
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Can't get tkinter database aware cascading comboboxes to update properly dford 6 3,536 Jan-11-2022, 08:37 PM
Last Post: deanhystad
  Print Values from a Sequence of Entries / ComboBoxes MC2020 4 2,750 Mar-28-2020, 10:05 PM
Last Post: MC2020
  [PyQt] making dependant comboBoxes Hitsugaya 3 4,961 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