Adding components to the Client Area of a Window with Menu Bar : MainWindow « GUI « Perl






Adding components to the Client Area of a Window with Menu Bar

 

#!/usr/bin/perl -w

use Tk;

$main = MainWindow->new();
$menubar = $main->Frame(-relief=>"raised",
                        -borderwidth=>2);

$filebutton = $menubar->Menubutton(-text=>"File",
                                   -underline => 0);  # F in File

$filemenu = $filebutton->Menu();

$filebutton->configure(-menu=>$filemenu);

$filemenu->command(-command => \&open_choice,
                   -label => "Open...",
                   -underline => 0); # O in Open

$filemenu->separator();

$filemenu->command(-label => "Exit",
                   -command => \&exit_choice,
                   -underline => 1);  # "x" in Exit

$helpbutton = $menubar->Menubutton(-text=>"Help",
                                   -underline => 0);  # H in Help

$helpmenu = $helpbutton->Menu();

$helpmenu->command(-command => \&about_choice,
                   -label => "About TkMenu...",
                   -underline => 0); # A in About

$helpbutton->configure(-menu=>$helpmenu);
$filebutton->pack(-side=>"left");

$helpbutton->pack(-side=>"right");
$menubar->pack(-side=>"top", -fill=>"x");

$label = $main->Label(-text => "Main Area");

$label->pack(-side=>"top", 
             -expand=>1,
             -padx=>100, 
             -pady=>100);
MainLoop();

sub exit_choice {
    print "You chose the Exit choice!\n";
    exit;
}

sub open_choice {
    print "Open file\n";
}

sub about_choice {
    print "About tkmenu.pl\n";
}

   
  








Related examples in the same category

1.Create empty window
2.Destroy a window in button action
3.tkphone - Phone another X Display and have a line-mode conversation
4.Tk Configuration Options
5.Create two windows
6.Setting Border Width for Frame
7.Advanced Hello World program using two MainWindows