May-26-2019, 10:24 AM
Please see the following thread
https://python-forum.io/Thread-Namespace...th-imports
Consider learning classes for GUI code
https://python-forum.io/Thread-Classes-Class-Basics
The code below has comments on how to fix and improve the code.
https://python-forum.io/Thread-Namespace...th-imports
Consider learning classes for GUI code
https://python-forum.io/Thread-Classes-Class-Basics
The code below has comments on how to fix and improve the code.
# from tkinter import * # don't flood the namespace with * imports import tkinter as tk # add tk. infront of following tkinter objects checkbox_texts = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", ] # give variables a more descriptive name checkbox_variables = [] def done_press(): # for x in range(len(data)): # don't use the index to iterate the items # print(button_list[x].get()) for checkbox in checkbox_variables: # iterating the items directly print(checkbox.get()) play = tk.Tk() # row=[1,2,3,4,5,6,7,8,9] # not required can use enumerate on list items tk.Label(play, text="Whats on").grid(row=0, column=0, padx=30, pady=20, columnspan=3) # for box in range(len(data)): # don't use the index to iterate the items for row, text in enumerate( checkbox_texts, 1 ): # iterate actual item and use enumerate to get row value checkbox_variable = tk.IntVar() # create the varibale button = tk.Checkbutton( play, text=text, variable=checkbox_variable ) # use text & checkbox_variable directly checkbox_variables.append(checkbox_variable) # append checkbox_variable button.grid(column=0, row=row, pady=5, padx=30) # row from enumerate btn_done = tk.Button(play, text="Done", command=done_press) btn_done.grid(column=0, row=11, columnspan=2) play.mainloop()