[Tutor] retrieving grid information

Alan Gauld alan.gauld at yahoo.co.uk
Mon Sep 28 18:15:49 EDT 2020


Caveat, i tried to respond to this earlier in the week using my tablet
but it doesn't appear to have come to the list so here goes again...

On 24/09/2020 23:21, kass rass wrote:

> I have been using the grid() function of the tkinter module to organise
> widgets on the GUI window. And I often use the grid_info()['row'] and
> grid_info()['column'] functions to retrieve the row and column,
> respectively, for a particular widget. 

Ok, That's a pretty unusual thing in my experience since it would imply
you are moving widgets around on the screen, which is usually the job of
the layout manager and you shouldn't need to change it. But if you must...

> But suppose I have a number of
> widgets on my window grid, if I know the row and column number of a
> particular location on the grid, how can retrieve the widget at that
> particular location?

That's an even more unusual ask, normally you might know the screen
coordinates but knowing the grid coordinates but not the widget
is a scenario I can't even think of occurring in normal use.

However, if it did happen you could ask the parent widget for a list of
it's children then ask each child for its grid coordinates(using the
methods you mentioned) and compare them to your required values.

That seems like a slow process but given the real-world number of
widgets within a single grid layout(normally less than a couple
of dozen) it shouldn't be a problem.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list