Reputation: 11
In tkinter, is there a way for me to reference a widget within a grid by its row and column, in the same way that you would be able to reference an item within a list (or list of lists) by knowing its position in the list?
Upvotes: 1
Views: 3039
Reputation: 11
Actually, I realised that I could solve my own problem in a much simpler way, by literally making a list of lists, with each sub-list containing all of the widgets for a single row, and therefore I can refer to each item through it's row and column.
Upvotes: 0
Reputation: 9622
You can call the .grid_slaves(row, column)
method on the parent widget; this will return a list (possibly empty) of the widgets in that cell.
You could also iterate over all of the child widgets (.grid_slaves()
with no parameters, or .winfo_children()
) and call .grid_info()
on each one. This returns a dictionary with 'row'
and 'column'
keys, along with various other grid parameters.
Upvotes: 7