Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi
i am learning perl tk on windows xp using activestate perl 5.10 with tk 804.028.0.0, the following example about a menubar composed from the main item "File" and two subitems "Open file", "Save as"
when i click on the "File" there is a line between it and the other subitems, by luck i have clicked on this line as this picture http://img23.imageshack.us/img23/184/tkmenu1.jpg and strangly another window have appeared; and on every click on this line another window appears as this picture http://img30.imageshack.us/img30/6304/tkmenu2.jpg.
the first window is the parent and closing it will close all other childs. but closing a child windows will close only that window.
what is the procedure on which clicking on this line invoke a child window ?
is this the same behaviour in linux?
thanks
#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = tkinit; my $menubar = $mw->Menu(-type => 'menubar'); $mw->configure(-menu => $menubar); my $text1 = 'File'; my $text2 = 'Open file'; my $text3 = 'Save as'; my $menu = $menubar->cascade(-label => $text1); $menu->command(-label => $text2); $menu->command(-label => $text3); MainLoop; __END__

Replies are listed 'Best First'.
Re: perl TK strange case
by stefbv (Priest) on Dec 17, 2009 at 12:22 UTC

    It's normal behavior and it works the same on Linux, see Tk::Menu -> TEAR-OFF ENTRIES.

    It's used for detaching the popup window, you can control it with the tearoff option:

    my $menu = $menubar->cascade(-label => $text1, -tearoff => 0);
Re: perl TK strange case
by Kirsle (Pilgrim) on Dec 18, 2009 at 00:10 UTC

    Tear-off menus are a relic from the old Unix days, where it was common for apps to have tear-off menus. The Gimp even nowadays has the option to tear menus off (if I recall correctly, even the Windows version can do this) - but I think in the Gimp it's disabled by default, but you can turn it on in the settings.

    Menus that tear off are confusing to Windows users, though, so you'll most likely want to set the -tearoff=>0 option. You can also set the option globally for all menus by doing this:

    $mw->optionAdd ('*tearOff', 'false');

    With this you won't need to specify a -tearoff setting for all your menus individually.