Jan-23-2021, 10:05 PM
I believe "grid" is the layout manager "grid" from tk. I don't know what kind of widgets are placed in "piece_counter" so I guessed Entry.
.grid() tells tk where to put the widget using the grid layout. The return value from grid() is None. You should not string widget creation and placement commands together if you want to keep the widget handle.
import tkinter as tk COLUMNS = 7 ROWS = 7 root = tk.Tk() piece_counter = [] for c in range(COLUMNS): for r in range(ROWS-1, -1, -1): entry = tk.Entry(root, width=4) entry.grid(row=r, column=c, padx=0, pady=0, sticky=S) piece_counter.append(entry)After this code executes you should have 49 Entry widgets in piece_counter[] and there should be 49 entry widgets arranged in a grid pattern in the root window.
.grid() tells tk where to put the widget using the grid layout. The return value from grid() is None. You should not string widget creation and placement commands together if you want to keep the widget handle.
# entry == None after this call entry = tk.Entry(root, width=4).grid(row=r, column=c, padx=0, pady=0, sticky=S) # entry has the Entry widget handle afer this call entry = tk.Entry(root, width=4) entry.grid(row=r, column=c, padx=0, pady=0, sticky=S)To call .grid() you need a widget handle. This code crashed because you didn't make any widgets. piece_counter is an empty list, so this results in an index error
piece_counter[piece_index].grid(...