I wanted to make a multi-selection dropdown list in Tkinter so browsing online I came to the solution of using add_checkbuttons
into a menu. The solution it's working, at least graphically, but now I want the GUI to actually do something when a check is marked. I tried with a simple function that print the value as a command for each check button but it's only being called once.
Here's my code so far:
root = tk.Tk()
groceries = ['Apple', 'Banana', 'Carrot']
def print_groceries(bucket,item):
print(bucket[item].get())
menubar = tk.Menu(root)
viewMenu = tk.Menu(menubar, tearoff = 0)
bucket={}
for item in groceries:
bucket[item] = tk.BooleanVar(False)
viewMenu.add_checkbutton(label = item, variable = bucket[item], command=print_groceries(bucket,item))
menubar.add_cascade(menu = viewMenu, label = "Buy")
root.config(menu = menubar)
root.mainloop()