Tkinter Geometry management

Tkinter Geometry management

Geometry Management


All Tkinter widgets have access to the specific geometry management methods, which have the purpose of organizing widgets throughout the parent widget area. Tkinter exposes the following geometry manager classes: pack, grid, and place.

  • The pack() Method - This geometry manager organizes widgets in blocks before placing them in the parent widget.
  • The grid() Method - This geometry manager organizes widgets in a table-like structure in the parent widget.
  • The place() Method - This geometry manager organizes widgets by placing them in a specific position in the parent widget.

Tkinter pack() Method


This geometry manager organizes widgets in blocks before placing them in the parent widget.

Syntax

widget.pack( pack_options )

Here is the list of possible options-

  • expand: When set to true, widget expands to fill any space not otherwise used in widget's parent.
  • fill: Determines whether widget fills any extra space allocated to it by the packer, or keeps its own minimal dimensions: NONE (default), X (fill only horizontally), Y (fill only vertically), or BOTH (fill both horizontally and vertically).
  • side: Determines which side of the parent widget packs against: TOP (default), BOTTOM, LEFT, or RIGHT.

Tkinter grid() Method


This geometry manager organizes widgets in a table-like structure in the parent widget.

Syntax

widget.grid( grid_options )

Here is the list of possible options-

  • column : The column to put widget in; default 0 (leftmost column).
  • columnspan: How many columns widgetoccupies; default 1.
  • ipadx, ipady :How many pixels to pad widget, horizontally and vertically, outside v's borders.
  • row: The row to put widget in; default the first row that is still empty.
  • rowspan : How many rowswidget occupies; default 1.
  • sticky : What to do if the cell is larger than widget. By default, with sticky='', widget is centered in its cell. sticky may be the string concatenation of zero or more of N, E, S, W, NE, NW, SE, and SW, compass directions indicating the sides and corners of the cell to which widget sticks.
  • padx, pady : How many pixels to pad widget, horizontally and vertically, outside v's borders.

Tkinter place() Method


This geometry manager organizes widgets by placing them in a specific position in the parent widget.

Syntax

widget.place( place_options )

Here is the list of possible options-

  • anchor : The exact spot of widget other options refer to: may be N, E, S, W, NE, NW, SE, or SW, compass directions indicating the corners and sides of widget; default is NW (the upper left corner of widget)
  • bordermode : INSIDE (the default) to indicate that other options refer to the parent's inside (ignoring the parent's border); OUTSIDE otherwise.
  • height, width : Height and width in pixels.
  • relheight, relwidth :Height and width as a float between 0.0 and 1.0, as a fraction of the height and width of the parent widget.
  • relx, rely : Horizontal and vertical offset as a float between 0.0 and 1.0, as a fraction of the height and width of the parent widget.
  • x, y : Horizontal and vertical offset in pixels.

No comments:

Post a Comment

INSTAGRAM FEED

@vipulpedia