O'Reilly logo

Mastering Perl/Tk by Nancy Walsh, Stephen Lidie

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Win32 System Menu Item

It’s possible to add menu items to the Win32 System menubutton (the button at the top-left of a Perl/Tk window, labeled with the red Tk letters in script). Based on the operating system identifier, $^O, this code conditionally adds a command menu item that executes a DOS pipeline.

if ($^O eq 'MSWin32') {
    my $syst = $menubar->cascade(-label => '~System');
    my $dir = 'dir | sort | more';
    $syst->command(
        -label   => $dir,
        -command => sub {system $dir},
    );
}

Figure 12-3 illustrates.

A System menu item that pages a sorted dir command

Figure 12-3. A System menu item that pages a sorted dir command

Figure 12-4 shows a DOS window and the contents of a particular directory. Then a Perl/Tk program is started and the “dir | sort | more” button is clicked; note the unsolicited, sorted directory listing.

Output from pressing the “dir | sort | more” System menu button

Figure 12-4.  Output from pressing the “dir | sort | more” System menu button

The special menu item labeled “Tearoff” is really a tearoff menu item that, when clicked, tears off only the Tk portion of the System menu.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required