in reply to Placement of image with Tk::Compound and Tk::Menu

If you read the docs on Tk::Menu under image you will see:
-image => value Specifies an image to display in the menu instead of a text string + or bitmap The image must have been created by some previous invocati +on of image create. This option overrides the -label and -bitmap opti +ons but may be reset to an empty string to enable a textual or bitmap + label to be displayed. This option is not available for separator or + tear-off entries.
Telling you to go look at the Tk::Image module to create the image.

If you want to use the 'images' from the Tk::Toolbar I think you will have to use the -bitmap option on the menu item rather than -image.

In addition, you have not used a geometry manager on your widgets in the code you showed us, so you wouldn't see anything anyway! Even the very simple example in Tk::Compound will give you some clues:

my $b = $parent->Button; my $c = $b->Compound; $b->configure(-image => $c); $c->Line; $c->Bitmap(-bitmap => 'warning'); $c->Space(-width => 8); $c->Text(-text => "Warning", -underline => 0); $b->pack;

jdtoronto

Replies are listed 'Best First'.
Re^2: Placement of image with Tk::Compound and Tk::Menu
by Anonymous Monk on Jul 05, 2006 at 03:35 UTC
    Do you know Tk::Compound?

    It makes it possible to combine text and image and is a way to create menuitmes with both images and text in perl/Tk.

    Problem is how can I place image to far left in menu (left justify it, that is)?

      Yes, the answer is GEOMETRY MANAGER.
      #!/usr/bin/perl -w use strict; use Tk; use Tk::Compound; my $parent = MainWindow->new(); my $b = $parent->Button; my $c = $b->Compound; $b->configure(-image => $c); $c->Line; $c->Bitmap(-bitmap => 'warning'); $c->Space(-width => 8); $c->Text(-text => "Warning", -underline => 0); $b->pack(-side => 'left'); MainLoop();
      This is the example code from Tk::Compound's documentation with a couple of things added to make it runnable. Note the addition of  -side => 'left' as an option to the pack command. Tk::pack is not my genoetry manager of choice, but it is simple for this demonstration. I would suggest developing amore than nodding acquaintance with "Mastering Perl/Tk" by Lidie and Walsh, published by O'Reilly.

      jdtoronto

        Menubar doesn't need packing (did you even run my example code?)
        Maybe you didn't have Tk:ToolBar installed - but check updated example code above which uses a builtin bitmap instead.

        You use Tk::Compound widget on a Button widget but I'm using it on a command menuitem on a menubar.