http://qs1969.pair.com?node_id=904291

ZJ.Mike.2009 has asked for the wisdom of the Perl Monks concerning the following question:

The following piece of code demonstrates my problem. Where am I doing wrong? Thanks for any help.
use warnings; use strict; package MyApp; use Wx qw(:everything); use base 'Wx::App'; #Loads a 16x16 BMP image my $bmp = Wx::Bitmap->new("exit.bmp",wxBITMAP_TYPE_BMP); sub OnInit { my $frame = Wx::Frame->new(undef,-1,'Menu Icon Test'); # Creates menus my $menu1 = Wx::Menu->new(); my $menu1item = $menu1->Append(wxID_EXIT, "Exit"); # I'm trying to set menu item icon here... # but the image does not show as expected $menu1item->SetBitmap ( $bmp ); # Creates menu bar my $menubar = Wx::MenuBar->new(); $menubar->Append($menu1, "File"); # Attach menubar to the window $frame->SetMenuBar($menubar); $frame->Show(); } MyApp->new->MainLoop;

Replies are listed 'Best First'.
Re: How do I set the menu item icon in wxPerl?
by Anonymous Monk on May 12, 2011 at 07:36 UTC
    Once you Append its too late change it
    my $item = Wx::MenuItem->new( $parent ... ); $item->SetBitmap( ... ); $parent->Append( $item );
      Thank you, Anonymous Monk! This is very enlightening! :)