Tkinter Anchors



Anchors are used to define where text is positioned relative to a reference point.

Here is list of possible constants, which can be used for Anchor attribute.

  • NW
  • N
  • NE
  • W
  • CENTER
  • E
  • SW
  • S
  • SE

For example, if you use CENTER as a text anchor, the text will be centered horizontally and vertically around the reference point.

Anchor NW will position the text so that the reference point coincides with the northwest (top left) corner of the box containing the text.

Anchor W will center the text vertically around the reference point, with the left edge of the text box passing through that point, and so on.

If you create a small widget inside a large frame and use the anchor=SE option, the widget will be placed in the bottom right corner of the frame. If you used anchor=N instead, the widget would be centered along the top edge.

Example

The anchor constants are shown in this diagram −

anchor_constants
python_gui_programming.htm
Advertisements