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

how to prevent button from resetting its size

15 views
Skip to first unread message

Zhao Wu

unread,
Apr 7, 2003, 7:03:55 PM4/7/03
to
I need to dynamically resize a button. However, after I changed the
size with GeometryRequest(), it automatically resets to the original
size after I click it. Does anyone know how to prevent this from
happening?

Marc Dashevsky

unread,
Apr 7, 2003, 7:18:45 PM4/7/03
to
zha...@pmc-sierra.com says in article <8ec9eeab.03040...@posting.google.com>:

What happens when you use -width and -height to resize the button?

--
Marc Dashevsky -- Remove '_' from address if replying by e-mail.

Jack D.

unread,
Apr 8, 2003, 3:03:51 AM4/8/03
to
"Zhao Wu" <zha...@pmc-sierra.com> wrote in message
news:8ec9eeab.03040...@posting.google.com...

GeometryRequest doesn't work that well for this....and the -height option is
determined by the text size. So, you use an image instead !

#### Button Resizer ####
#!/usr/bin/perl

use Tk;
use Tk::Compound;
use strict;
my $multiplier=1;
my $mw=tkinit;

my $thinbutton = $mw->Button;
my $c = $thinbutton->Compound;
$c->Text(-text => "Slim Button");
$thinbutton->configure(-image => $c,-height=>$multiplier*10);
$thinbutton->pack(-side=>'left');
$mw->Scale(
-variable=>\$multiplier,
-from=>1,
-to=>5,
-command=>[\&resize_button,$thinbutton])->pack(-side=>'right');
MainLoop;

sub resize_button
{
my $b=shift;
$b->configure(-height=>$multiplier*10);
}
__END__
--
Jack D.
Remove '__' from address if replying by e-mail.


Zhao Wu

unread,
Apr 9, 2003, 10:51:50 PM4/9/03
to
Jack,
Thanks for your post, but it doesn't seem to work in the following
example:
(after you shrink the button and click on it, it resumes the original
size)

use Tk;
{
package Tk::foo;
use base qw(Tk::Frame);
Tk::Widget->Construct('foo');
use Tk::Compound;

sub Populate
{
my $mw = shift;
my $box = $mw->Listbox;
my $thinbutton = $mw->Button(-command => sub{
$box->insert('end','foo')});


my $c = $thinbutton->Compound;
$c->Text(-text => "Slim Button");
$thinbutton->configure(-image => $c,-height=>$multiplier*10);

my $adj = $mw->Frame(qw/-width 2 -bg black -borderwidth 1 -relief
sunken -cursor sb_h_double_arrow/)
->pack(qw/-fill y -side right -expand 1/);
$adj->bind('<B1-Motion>', sub{
my $pixels = $mw->pointerx - $mw->rootx - 8;
if ($pixels > 0) {
$thinbutton->configure(-width => $pixels);
$box->GeometryRequest($pixels, $box->height);
}
});
$thinbutton->pack(qw/-side top -fill x -expand 0/);
$box->pack(qw/-side bottom -fill both -expand 1/);
}
}

my $mw=tkinit;
$mw->foo->pack(qw/-side left fill both -expand 0/);
$mw->foo->pack(qw/-side left fill both -expand 0/);
MainLoop;

"Jack D." <goodc...@hotmail.com> wrote in message news:<rvuka.16363$B54.2...@news1.telusplanet.net>...

Jack D.

unread,
Apr 10, 2003, 4:33:19 AM4/10/03
to
"Zhao Wu" <zha...@pmc-sierra.com> wrote in message
news:8ec9eeab.03040...@posting.google.com...
> Jack,
> Thanks for your post, but it doesn't seem to work in the following
> example:
> (after you shrink the button and click on it, it resumes the original
> size)

Hmm....your original post didn't say you were using GeometryRequest on a listbox
:-)

The point I was trying to make is to 'avoid' using GeometryRequest ... period.
You asked about resizing a button, to which I gave a possible solution (without
using GeometryRequest). A listbox, that is another problem altogether.

There may be a few options to consider.

1. Try the original Tk::Adjuster
2. Try using the 'form' geometry manager to lock the sides of the listbox and
adjuster to follow the button. Then only adjust the size of the button.
3. Yucky but possible - use fontMetrics to determine the character width needed
based on your button width.

Jack


0 new messages