Book HomeMastering Perl/TkSearch this book

12.3. 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.

Figure 12-3

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.

Figure 12-4

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.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.