Build menu items for main windows : Menu « GUI « Perl






Build menu items for main windows

   

use Tk;

my $main = MainWindow->new();

$menubar = $main->Frame()->pack('-side' => 'top', '-fill' => 'x');

$filemenu = $menubar->Menubutton('-text' => 'File')->pack('-side' => 'left');

$filemenu->command('-label' => 'Open', '-command' => sub
    {$text->delete('1.0', 'end');
    $text->insert('end', "You clicked open.");});

$filemenu->separator();

$filemenu->command('-label' => 'Exit', '-command' => sub {exit});

$editmenu = $menubar->Menubutton('-text' => 'Edit')->pack('-side' => 'left');

$editmenu->command('-label' => 'Search', '-command' => sub
    {$text->delete('1.0', 'end');
    $text->insert('end', "You clicked search.");});

$editmenu->command('-label' => 'Replace', '-command' => sub
    {$text->delete('1.0', 'end');
    $text->insert('end', "You clicked replace.");});

$text = $main->Text ('-width' => 40, '-height' => 3)->pack();

MainLoop;

   
    
    
  








Related examples in the same category

1.CheckBox Menu
2.RadioButton Menu
3.Adding MenuItem to Menu Bar
4.Adding Action to MenuItem
5.Packing the MenuItem on a Menu Bar: left
6.Packing the MenuItem on a Menu Bar: right
7.Set Text for MenuItem
8.Adding the Menu Bar to Main Window
9.Setting the Underline Character for MenuItem
10.Adding Separator