Jun-21-2023, 06:54 PM
(This post was last modified: Jun-21-2023, 06:54 PM by Gribouillis.)
You could also store the row and column as attributes in the Button instance
from functools import partial from tkinter import * root = Tk() root.title(" ") root.geometry("250x250+0+20") def button_print(button): print(f"{button.row + 1}, {button.column + 1}") buttons = [] for grid_row in range(3): button_row = [] for grid_column in range(3): button = Button(root, text = f"{grid_row + 1} {grid_column + 1}", width = 4, height = 3) button.row = grid_row button.column = grid_column button.configure(command=partial(button_print, button)) button.grid(row = grid_row, column = grid_column, padx = (10, 10), pady = (10, 10)) button_row.append(button) buttons.append(button_row) root.mainloop()
(Jun-21-2023, 06:29 PM)Clunk_Head Wrote: Is there a GUI alternative that is natively capable of achieving my goal?I think all GUIs including tkinter allow you to attach client data to a widget and to retrieve this client data when a callback is invoked.