[Tkinter-discuss] pack: difference between anchor and side options? (also anchor as a widget option)
duffy at quinda.com
Sat Jul 4 05:04:34 CEST 2009
In case others are led to this thread by a Google of tkinter pack anchor
just as I was, I wanted to contribute my example and how I overcame the two gotchas that I encountered while solving it.
To visualize the interplay between anchor and side, think of the behavior of layout manager when doing a row of boats moored at a dock. The dock is a Frame, rowOfBoats is another Frame packed with "side": "top" so that the bows of the boat point upward towards the dock. Each of the boats are "side": "left" within rowOfBoats so that they form a row, with their bows pointing upward.
If all the boats are the same length, their noses will touch the dock.
If all the boats are not the same length, only the nose of the longest one will touch the dock. The others are centered within a space the size of the longest one, so their noses are a little ways away from the dock.
Instead make the boats "anchor": N, "side": "left" within rowOfBoats, and every boat will have its nose touching the dock.
The gotchas I mentioned: first was coding "anchor": "N", "side": "left" since all the other options are strings. That will produce an exception _tkinter.TclError: bad anchor "N": must be n, ne, e, se, s, sw, w, nw, or center
The other gotcha: I tried coding rowOfBoats as "anchor": N, "side": "top" below dock, without adding "anchor": N to the pack for individual boats. More subtle since it gave no error, it just didn't do anything--leaving the appearance unchanged as though my code change was not being executed.
- Duffy O'Craven
More information about the Tkinter-discuss