0

I'm pulling my hair out and sure I'll be embarrassed by how simple my mistake is. I have created a Combobox which is supposed to launch a function each time is it selected. However nothing happens when you pick a different selection.

Here's the code:

acc_drop_box = ttk.Combobox(mainframe, textvariable=acc_value)
acc_drop_box['values'] = acc_list
acc_drop_box.grid(column=1, row=2, sticky=(W, E))
acc_drop_box.bind('<<ComboboxSelected>>', pick_acc(acc_value))

Right now the function "pick_acc" just prints the word "Hi!" for testing purposes. That happens once when I launch the program but not again no matter what I do. Thanks for your help!

Nae
  • 12,111
  • 5
  • 46
  • 74
Tom
  • 881
  • 2
  • 8
  • 21

1 Answers1

0

You're giving the return of the callback as the reference as opposed to callback's reference. Replace:

acc_drop_box.bind('<<ComboboxSelected>>', pick_acc(acc_value))

with:

acc_drop_box.bind('<<ComboboxSelected>>', lambda var=acc_value: pick_acc(var))
Nae
  • 12,111
  • 5
  • 46
  • 74
  • This works! Awesome thanks. As for it being duplicate, I can see that it is. I didn't find this because I was looking for Combobox specifically. – Tom Mar 24 '18 at 13:49