Ok, so this is what I have: We can use the -hidemargin to force image in menuitem (using Tk::Compound) to the far left.

There are two major problems left:

1) Image used in menuitem does not appear properly before it is hoovered over by mouse pointer.
2) "Hook" of checkbutton now has disappeared. Where did it go?

Example code demoonstrates these issues.

#!/usr/bin/perl -s use Tk; use Tk::ToolBar; use Tk::Compound; use strict; my $mw = MainWindow->new(); #Load images from Tk::ToolBar. my $tb = $mw->ToolBar(); $tb->destroy(); my $compound = $mw->Compound; $compound->Image( -image => 'acthelp16', -anchor => 'w' ); $compound->Space( -width => 8 ); $compound->Text( -text => "Open", -underline => 0 ); $compound->Space( -width => 28 ); my $menubar = $mw->Menu( -type => 'menubar', ); my $c2 = $mw->Compound; $c2->Space(-width => 40); $menubar->cascade( -label => 'File', -tearoff => 0, -menuitems => [ #Problem 1: Image is now shown properply before we #hoover over menuitem. [ Command => 'Open', -image => $compound, -hidemargin => 1, ] +, '-', #Problem2: When we are using hidemargin, the "hook" #of the checkbutton doesn't appear anymore. [ Checkbutton => 'Checkthing', -hidemargin => 1, -image=>$c2, + -compound=>'left', ], ] ); $mw->configure( -menu => $menubar ); MainLoop;
Update:
Ok, I've figured this out now. It appears that we have to set up an after timer with -postommand to configure images as menu is shown to get them to display correctly. This is might be bug on win32 only!? Bitmaps seems to display fine without this hack.

CheckButton indicator is removed when -hidemargins is enabled. Nothing to do about that. Solution for me is to move all CheckButton menuitems to a seperate cascade menu where we turn off -hidemargins and populate with CheckButton menuitems only.

Update (for later reference):
Ok, seems like xpm images, created with the Pixmap()-method, work ok with menus on win32. Then we can avoid "-postcommand fix" ,which create ugly flash when many icons are used, and use icons with lots of colors (unlike bitmaps).
Tools "any to icon"/"icon to any" can convert images to .ico/xpm-files.


In reply to Re: Placement of image with Tk::Compound and Tk::Menu by ldln
in thread Placement of image with Tk::Compound and Tk::Menu by ldln

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.