in reply to Re: Tk! (entrycget w/ 'active')
in thread Tk! (entrycget w/ 'active')
The core of the solution is <<MenuSelect>>, which gets a promising single reference in Tk::Menu,#!/usr/bin/perl use warnings; use strict; use Tk; my $MW = MainWindow->new; my $menu = $MW -> Menu(-type=>'menubar',-tearoff=>0); $MW -> configure(-menu=>$menu); $MW -> bind('Tk::Menu',"<Key-F1>"=>[\&printentry]); # the class bindin +g my %MM = (); my %MC = (); my %ME = (); $MM{one} = $MW -> Menu(-tearoff=>0); $MC{one} = $menu -> cascade(-menu=>$MM{one},-label=>'one',-underline=> +0,-tearoff=>0); $ME{Ia} = $MM{one} -> command(-label=>'Ia',-command=>sub{exit}); $ME{Ib} = $MM{one} -> command(-label=>'Ib',-command=>sub{exit}); $ME{Ic} = $MM{one} -> command(-label=>'Ic',-command=>sub{exit}); $MM{two} = $MW -> Menu(-tearoff=>0); $MC{two} = $menu -> cascade(-menu=>$MM{two},-label=>'two',-underline=> +0,-tearoff=>0); $ME{IIa} = $MM{two} -> command(-label=>'IIa',-command=>sub{exit}); $ME{IIb} = $MM{two} -> command(-label=>'IIb',-command=>sub{exit}); $ME{IIc} = $MM{two} -> command(-label=>'IIc',-command=>sub{exit}); my $label; my %name=(); $menu -> bind('<<MenuSelect>>' => sub { # works only on "Menu" $label = undef; # NOT "cascade" my $this = $Tk::event->W; Tk::catch {$label = $this->entrycget('active',-label)}; }); my $x; foreach $x (keys %MM) { $MM{$x} -> bind('<<MenuSelect>>' => sub { $name{$x} = undef; my $that = $Tk::event->W; Tk::catch {$name{$x} = $that->entrycget('active',-labe +l)}; }); } MainLoop; sub printentry { print "hello $label\t$name{$label}\n" }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Tk! (entrycget w/ 'active')
by eserte (Deacon) on Mar 10, 2008 at 23:02 UTC |