Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Window not getting <Configure> events when using grid

29 views
Skip to first unread message

keithv

unread,
Jun 9, 2016, 9:25:43 PM6/9/16
to
It seems if you use grid to place a widget such as a canvas and then you manually shrink the window with the mouse, you don't get any Configure events and "winfo width .c" doesn't reflect reality.

This doesn't happen if you use pack instead of grid, or if the grid gets configured with a -weight value.

Any idea how to work around this?

Here's a short script showing the issue:

package require Tk

proc DisplaySize {who} {
.c itemconfig txt -text "$who: [winfo width .c]x[winfo height .c]\n[.c itemcget txt -text]"
}

canvas .c -width 400 -height 600 -bg gray75 -bd 0 -highlightthickness 0
.c create text 10 10 -anchor nw -tag txt -text "start: 400x600"
#pack .c
grid .c
bind .c <1> {DisplaySize click}
bind .c <Configure> {DisplaySize config}


Keith

Rich

unread,
Jun 9, 2016, 10:45:54 PM6/9/16
to
This is because the grid default for row/column -weight values is zero, and
zero is documented as "A weight of zero (0) indicates the [column/row]
will not deviate from its requested size." As well, the default anchor
for grids is nw. So with a default zero weight and default anchor of
nw, when the toplevel changes size, the size of the contained window
does not change (weight 0) nor does the position of the contained
window change (nw anchor) and so no configure event is delivered.

You can see (or, at least on Linux I can see) that .c's size and
position within the toplevel does not change by enlarging the toplevel
(or at least on Linux enlarging the toplevel shows a dark grey 400x600
canvas window sitting in the north west corner of a larger slightly
lighter grey toplevel window. The result is the contained canvas
remains 400x600 and at 0,0 in the toplevel even when the toplevel grows
or shrinks.

You get a configure when you pack the canvas because pack's default
position is top and default anchor is center. So packing the canvas
makes it stick to the top of the toplevel window, but be centered
within the space within the toplevel. So when the toplevel changes
size, the position of the canvas changes within the toplevel, and a
configure event results. The size with pack remains 400x600 because
the size of the canvas did not change (-expand and -fill default of off
and none respectively for pack).

0 new messages