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

Home
Perl
1.Array
2.CGI
3.Class
4.Data Type
5.Database
6.File
7.GUI
8.Hash
9.Language Basics
10.Network
11.Regular Expression
12.Report
13.Statement
14.String
15.Subroutine
16.System Functions
17.Win32
18.XML
Perl » GUI » MainWindow 




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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.