Advanced Search
Mail us
Home    Manuel    Links    Faq    Submit a tcl/tk Reference    Contact Us

    Some examples tcl/tk codes     Man of Bwidget     Man of blt     mkwidget screenshots     TkOgl     Video Demo real.

  avoid fractional white space at the end of a resizable listbox?
 First, let`s state the problem more clearly. I want to make a
resizable listbox and I don`t want to constrain it by setting a
minimum size. So I pack it with fill expand, I use it to set the grid
(so that resizing the window always gives me whole lines) and I set an
initial geometry of 1x1 to override the default. However what I get
is... (run the code below for a demo and try to resize)

listbox .l -geom 1x1 -setgrid 1 -yscrollcommand ".s set" -relief sunken -bd 2
scrollbar .s -command ".l yview"
pack .s -side right -fill y
pack .l -side top -fill both -expand 1
.l insert end one two three four five six seven eight nine ten "THE END"

...a situation where the partially filled listbox has a blank
half-line at the bottom even if there are more items in the list. This
is very confusing because it fools the user into thinking that there
is nothing else beyond what`s visible. Why does it happen?

Now for the answer.
	Look at the window as it is created, before the resizing. See that
poor, tiny little scrollbar squeezed in that microscopic window? It,
too, requests a minimum size, and it so happens that the starting
geometry for the listbox (i.e. the situation referred to as "1x1")
receives some free fractional space at the bottom. And you never get
rid of it, since the resizing is constrained to be in whole

The thing to do is to define the initial layout in such a way that the
widget that has -setgrid actually displays an integer number of lines
and columns. In the above example, setting -geom 1x2 does the trick.

Thanks to Frank Stajano  for this tip.