I am trying to print the values of the checkboxes I select. Can someone help point me in the right direction? I am getting an error on this line - print(my_items[item])
This is the error:
TypeError: list indices must be integers or slices, not IntVar
import tkinter as tk
from tkinter import *
top = tk.Tk()
top.wm_title("Checklist")
my_items = ['pizza','breadsticks','wings','CocaCola','brownie']
check_boxes = {item:IntVar() for item in my_items}
def confirm():
for item in check_boxes.values():
if item.get() == 1:
print(my_items[item])
for item in my_items:
CB = Checkbutton(top, text = item, variable = check_boxes[item], anchor = W, onvalue = 1, offvalue = 0, height=1, width = 50)
CB.pack()
B1 = tk.Button(top, text = "confirm", command = confirm)
B1.pack()
top.mainloop()
print( item ). Listmy_itemsneeds number butitemis not number. You have to rewrite all in different way. Why don't getkeysfrom dictionary?