Ok, understood. If I change items to:
my $menuitem = [ [command => 'Open', -image => $compound], [comman
+d => 'close'] ];
Then the left edge of the ? lines up with the left edge of close - that is, there is only as much space to the left of either entry as I would expect. Indeed, if I add an edit menu with two plain entries:
$menuitem = [ [command => 'Open'], [command => 'close'] ];
$menubar->cascade(-label => 'Edit', -tearoff => 0, -menuitems => $
+menuitem);
I see the same amount of space to the left of the entries there.
However, I can see your issue - the space to the left is excessive and other programs are capable of putting an icon there. Problem understood. :) No answer yet, but I'll look into it later tonight if you haven't an answer before then.
DWIM is Perl's answer to Gödel
| [reply] [d/l] [select] |
Had look at the widget demo and found a solution but other problems appeared also.
The solution is to use "-hidemargin =>1" option on each menuitem. I tried this option before posting my query, but apparently if we don't use "-hidemargin =>1" on all menuitems under a menubar entry, it just won't work. So it seems that indivdual menuitems can't be controlled - they all eiter have a margin or they don't. Well, I can live with that.
But now there are two other problems:
1) On the Checkbutton menuitem, the "hook" no longer appears.
2) The image from Tk::ToolBar doesn't appear properly before menuitem is highlighted. Same happens if I create own Tk::Image widget and use that instead.
How could we solve 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;
#How do we place this image to far left in menu?
#Answer:use -hidemargin option.
$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);
#my $menuitem = [ [ command => Open, -image => $compound ] ];
$menubar->cascade(
-label => 'File',
-tearoff => 0,
-menuitems => [
#All menuitem must have hidemargin enabled for it to work.
[ Button => 'Open', -image => $compound, -hidemargin => 1, ],
[ Button => '~Quit', -command => [ destroy => $mw ], -hidemar
+gin => 1 ],
'-',
#But now the checkbutton doesn't appear anymore..
[ Checkbutton => 'Checkthing', -hidemargin => 1, -image=>$c2,
+ -compound=>'left' ],
]
);
$mw->configure( -menu => $menubar );
MainLoop;
| [reply] [d/l] |