in reply to Re^2: $menu->insert problem in Perl/Tk
in thread $menu->insert problem in Perl/Tk

entryconfigure ?

Replies are listed 'Best First'.
Re^4: $menu->insert problem in Perl/Tk
by thundergnat (Deacon) on Jun 10, 2005 at 11:09 UTC

    That sounds reasonable, but I can't figure out how to use entryconfigure to add child commands under the top level menu entry. If you can show me or point to a minmal working example it would be a huge help.

    Update: AHA! It turns out that entryconfigure IS usable to do what I am trying to do, it is just that the syntax of the command is quite arcane. I pieced this together from bits found in several places. Many thanks to spurperl for steering me in the right direction.

    #!/usr/bin/perl use strict; use warnings; use Tk; use Tk::Text; my $top = MainWindow->new; my $text = $top->Text->pack(-expand => 'yes', -fill => 'both'); my $menu = $text->menu; add_my_menu_item($menu, 2, 'bogus', $text); $top->configure(-menu => $menu); MainLoop; sub add_my_menu_item{ my ($menu, $index, $name, $widget) = @_; $menu->insert($index, 'cascade', -label => $name, -menu => $menu-> +entrycget($index, '-menu')->Menu( -tearoff => 0 )); my $entry = $menu->entrycget($index, '-menu'); map ( $entry->command ( -label => $_, -command => [sub {$widget->insert('insert', $_[0])}, $ +_], ) ,(qw/1 2 3 4 5/) ); }