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

buttons resize when image disappears

30 views
Skip to first unread message

Mark Tarver

unread,
Oct 31, 2017, 7:50:20 PM10/31/17
to
My card game is working. However I get a lot of movement in the window manager when I make images disappear off buttons. It seems that the buttons resize themselves. What I'd like to do is for the dimensions of the buttons to remain the same whether or not an image is on them. All images are the same size.

Mark

Rich

unread,
Oct 31, 2017, 9:32:40 PM10/31/17
to
Are you reconfiguring the button's -image setting to an empty string to
"disappear" the images?

If yes, then don't do it that way. Instead, create one more image, a
blank/empty one, the same size as all the others, and put it on the
button(s) when disappearing one of the real images.

So to "disappear" you'd now do ".b configure -image blank-image-name".

The same image name can appear on plural buttons at the same time.

Harald Oehlmann

unread,
Nov 1, 2017, 8:24:53 AM11/1/17
to
The size of the button may also be held by the geometry manager.
This is my favorite way to give a size to a widget.

Otherwise, you may manually set the size of the button like this:

pack [button .b -icon myicon]
.b configure -width [winfo width .b]
.b configure -icon ""

Just ideas,
Harald

Rich

unread,
Nov 1, 2017, 10:36:18 AM11/1/17
to
There's no "-icon" option for a button object, did you mean "-image"?

The problem with this method is that it is not documented to maintain a
pixel size (which appears to be what Mark wants, pixel size of button
does not change).

The button man page says (emphasis added here):

[-width width] Specifies a desired width for the button. If an
image or bitmap is being displayed in the button then the value
is in screen units (i.e. any of the forms acceptable to
Tk_GetPixels). *For a text button (no image or with -compound
none) then the width specifies how much space in characters to
allocate for the text label.*

And the options man page says (emphasis added here):

[-image image] Specifies an image to display in the widget, which
must have been created with the image create command.
Typically, if the -image option is specified then it overrides
other options that specify a bitmap or textual value to display
in the widget, though this is con- trolled by the -compound
option; *the -image option may be reset to an empty string to
re-enable a bitmap or text display.*

So the documented behavior of empty string to "-image" is to return to
text character sizing, and the pixel width of "winfo width .b" in text
characters is from the pixel width of the same in pixels.

Since Mark appears to want to show/hide images on buttons, his easiest
method to maintain an identical pixel size for the button [1] is to
swap the active image with a blank image of the same size rather than
toggling between text display and image display modes for the buttons.

[1] Yes, the geometry manager could also be forced into enforcing a
size as well, but one more AxB size blank image solves all the problems
with little fussing.

Mark Tarver

unread,
Nov 1, 2017, 2:05:53 PM11/1/17
to
That's the way I've done it. I've had to craft an image of the same size and colour as the background window. Took a bit of time.

Mark

Rich

unread,
Nov 1, 2017, 2:40:09 PM11/1/17
to
A 100% transparent image would let the existing background from the
button show through.

Gerald Lester

unread,
Nov 1, 2017, 3:43:21 PM11/1/17
to
Or he could have done a screen capture of the background and cropped it
to the right size.

--
+----------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald...@kng-consulting.net |
+----------------------------------------------------------------------+
0 new messages