Changing the Size of a Button
Normally the
size of the Button is automatically determined by the application and
is dependent on the text string or image displayed in the Button. The
width and height can be specified explicitly by using the
-width and -height options:
-width =>x, -height =>y
The values specified for x and
y vary depending on whether a bitmap/image
or text is displayed in the Button. When a bitmap or image is
displayed, the values in x and
y represent valid screen distances. If
text is displayed on the Button, x and
y are character sizes.
This example shows one Button that is the default size and another
drawn with -width of 10 and
-height of 10. (It is not necessary that the
amounts for -width and -height
be the same or that you use both options.)
$mw->Button(-text => "Exit",
-command => sub { exit })->pack(-side => 'left');
$mw->Button(-text => "Exit",
-width => 10, -height => 10,
-command => sub { exit })->pack(-side => 'left');In Figure 4-28, which illustrates this example, the second Button is much taller than it is wide, because text characters are taller than they are wide.

Figure 4-28. Default -width and -height (left) versus Button with -width and -height set (right)
The values specified for both
-width and -height are
characters, because the Button is displaying text. When
-width and -height are used with a bitmap, the amount specified is in screen distance. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access