Python Tkinter | grid_location() and grid_size() method
Tkinter is used to develop GUI (Graphical User Interface) applications. It supports a variety of widgets as well as a variety of widgets methods or universal widget methods.
grid_location() method –
This method returns a tuple containing (column, row) of any specified widget. Since this method is a widget method you cannot use it with master object ( or
Tk() object). In order to use this method, you should first create a
Frame and treat it as a parent (or master).
Syntax: widget.grid_location(x, y)
x and y are the positions, relative to the upper left corner of the widget (parent widget).
In below example,
grid_location() is used to get the location of the widget in the
grid_size() method –
This method is used to get the total number of grids present in any parent widget. This is a widget method so one cannot use it with master object. One has to create a
Syntax: (columns, rows) = widget.grid_size()
Return Value: It returns total numbers of columns and rows (grids).
Below is the Python code-
Every time you click the mouse button it will return the same value until more widgets are not added OR number of rows and columns are not increased.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course