pdsx has asked for the wisdom of the Perl Monks concerning the following question:

I need to dynamically adjust the width of a Tk::BrowseEntry's listbox in order to have it wide enough for the widest entry, depending on the font properties of the BrowseEntry.

Anybody dunnit?

Phil

  • Comment on Screen width of string in proportional font

Replies are listed 'Best First'.
Re: Screen width of string in proportional font
by lamprecht (Friar) on Jan 27, 2010 at 13:53 UTC
    Hi Phil,

    try this:

    use strict; use warnings; use Tk; my $mw = tkinit; my $s = 'text'; my $b = $mw->BrowseEntry->pack; $mw->Button(-text => 'add entry', -command => sub{$b->insert('end',$s.='-foo'); $b->updateListWidth; } )->pack; MainLoop;

    Cheers, Christoph
      Wow! Thanks! I was unaware of the 'updateListWidth' method. However, by looking at a more recent BrowseEntry Manpage I discovered the '-autolistwidth' option which seems to be exactly what I need.

      Thanks, Chris!

      Cheers, Phil