Version 4 of Tk widget sticky discussion

Updated 2006-05-08 06:32:40

Purpose: to provide examples to the beginning Tk programmer of how the -sticky configuration parameter works on the various Tk widgets that support the flag.


For instance:

 frame .addr -background orange
 grid  .addr -sticky we
 entry .addr.addr1 -width 30
 grid  .addr.addr1 -sticky we

The original author's expectation was that the field would be left justified and would expand. - RS would rather expect it to be centered, but fill all available space. Use -justify left for left justification :)

The originator wasn't talking about text within a label or whatever being justified. They were expecting the entry box to hang on the left of frame - me, I don't know why they expected that instead of centered... I certainly expected it centered.

The -sticky argument indicates the developer is specifying on which side(s) of a grid cell a widget should appear. The parms for the -sticky are one of the following:

  • n (north)
  • s (south)
  • e (east)
  • w (west)

or some reasonable combination of these flags.

So, a value of "we" would, in my mind, mean that a widget would be centered along the horizontal axis of the grid cell. A value of "ns" would indicate that a widget would be centered along the vertical axis of the grid cell. A value of "news" would, I presume, attempt to center the widget along both axies.

CRV Why doesn't this work?

 radiobutton .rbtDs -text "Description Group" -command {}
 labelframe .lbfDs -labelwidget .rbtDs
 frame  .lbfDs.fraDs         -bd 2 -relief sunken
 label  .lbfDs.fraDs.lblLDs  -text "Description"
 label  .lbfDs.fraDs.lblDs   -relief sunken -justify left
 button .lbfDs.fraDs.btnDlDs -text "X" -command {exit}

 grid .lbfDs
 grid .lbfDs.fraDs -stick ew
 grid .lbfDs.fraDs.lblLDs .lbfDs.fraDs.lblDs -sticky ew
 grid .lbfDs.fraDs.btnDlDs 

Even adding '-width 400' to either the 'labelframe' or the 'frame' will change the displayed width.


Category GUI