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

The code given is cut down as far as I can to demonstrate the problem. I have a Tk window, where I want a listbox with a label at the top. I also want to set the icon myself. The following code is intended to do this:
use strict; use warnings; use diagnostics; use Tk; my $cboAgent; my $mw = MainWindow->new; $mw->geometry('200x400'); $mw->toplevel->resizable(0,0); $mw->Label(-text => 'Agent' ) ->place(-x => 0, -y => 0 ); ($cboAgent) = $mw->Scrolled('Listbox', -height => 20, -width => 10, -scrollbars => 'e') ->place(-x => 0, -y => 25 ); $mw->toplevel->iconbitmap('C:\Template\v3_5\TARDISdv\Tardis.ico'); MainLoop;
This produces everything bar the listbox. However, if I comment out either the label or the icon commands (or both), I get the listbox. I have tried changing the order of the commands, but it doesn't seem to make a difference. However, I haven't tried every possible combination. Please would someone point out my stupidity? My system configuration is in my scratchpad. Update: WAS in my scratchpad. I didn't think it was relevant, and so it proved. But it's in my private scratchpad if anyone REALLY needs it. /update

TIA & regards,

John Davies

Replies are listed 'Best First'.
Re: Tk oddity with Label, iconbitmap and listbox
by thundergnat (Deacon) on May 28, 2005 at 20:06 UTC

    Just update the main window before you set the icon.

    use strict; use warnings; use diagnostics; use Tk; my $cboAgent; my $mw = MainWindow->new; $mw->geometry('200x400'); $mw->toplevel->resizable(0,0); $mw->Label(-text => 'Agent' ) ->place(-x => 0, -y => 0 ); ($cboAgent) = $mw->Scrolled('Listbox', -height => 20, -width => 10, -scrollbars => 'e') ->place(-x => 0, -y => 25 ); $mw->update; $mw->toplevel->iconbitmap('C:\Template\v3_5\TARDISdv\Tardis.ico'); MainLoop;
      Works perfectly. Many thanks! I didn't know about update - now I know what to look for in the man pages.

      Regards,

      John Davies