Jan-21-2020, 07:08 PM
one major issue with your code is it's not a class. here's a checkbox
import tkinter as tk class MainFrame(tk.Frame): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.vars=[] self.checkbuttons = {'pizza': tk.IntVar(), 'salad': tk.IntVar(), 'coffee': tk.IntVar()} for key, value in self.checkbuttons.items(): ctrl = tk.Checkbutton(self, text=key, variable=value) ctrl.pack() self.vars.append(value) self.button = tk.Button(self, text='Checkbutton values', command=self.on_button) self.button.pack(pady=5,padx=10) self.pack() def on_button(self): res= [] for key, val in self.checkbuttons.items(): select= val.get() if select: print(f'you selected {key}') if __name__ == '__main__': app = tk.Tk() main_frame = MainFrame() app.mainloop()