smh has asked for the wisdom of the Perl Monks concerning the following question:
I am writing code Perl TK. I am want to popup a widget such as “entry” or “label” at the mouse location in a tree widget. I have been trying ideas similar to what I have seen done with popup menu. I have read your peace “Tk::Wm::Popup” on CPAN. <\P>
"...For this discussion, we'll use the simple term dialog to refer any widget that pops up and awaits user interaction, whether it be a Menu, a special purpose Toplevel, or any of the dialog-type widgets, including, but not limited to, ColorEditor, Dialog, DialogBox, ErrorDialog, FileSelect, FBox, getOpenFile and getSaveFile. ..."
I assume that I should be able to able to popup simple widgets. Here is my test code.
use Tk; use Tk::Entry; use Tk::Tree; use Tk::Notebook; use warnings; use strict; my $mw = MainWindow->new(); my $nb = $mw->NoteBook( -font => 'Tahoma 8 bold', )->pack( -side => 'top', -anchor => 'ne', -expand => 1, -fill => 'both', ); my $tb = $nb->add( 'Tab 1', -label => 'Tab1', ); my $tree = $tb->Scrolled( 'Tree', -background => 'snow', -selectmode => 'extended', -selectbackground => '#E0FFCC', -selectforeground => 'red', -highlightthickness => 0, -relief => 'ridge', -borderwidth => 2, -scrollbars => 'osoe', -drawbranch => 'true', -indicator => 'true', -selectborderwidth => -1, -selectmode => 'extended', #-browsecmd => \&my_command, )->pack(-side => 'top', -anchor => 'nw', -expand => 1, -fill => 'both', ); # ##================================= # ## popup menu works fine # ##================================= # my $mb = $tree->Menu; # $tree->bind("<Button-3>" => sub { $mb->Popup( -popover => "cursor", # -tearoff => 0, # -popanchor => 'nw', # -overanchor => 'ne' # ) # } # ); # # my $mdel = $mb->cascade( -label => 'Delete', # -tearoff => 0, # ); # # $mdel->command( -label => "Delete", # -command => sub{ my @E = $tree->info( 'selection' ); # foreach my $e ( @E ) # { # $tree->delete( 'entry', $e); # } # } # ); ##================================= ## popup an entry that does NOT work ##================================= my $w = $tree->Frame(); $w->label( -text => 'popup label' ); $tree->bind("<Button-3>" => sub{ $w->Popup( -popover => "cursor", -popanchor => 'nw', -overanchor => 'ne' ) } ); MainLoop;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How to popup a widget such as “entry” or “label” at the mouse location
by zentara (Archbishop) on Mar 04, 2012 at 16:58 UTC | |
Re: How to popup a widget such as “entry” or “label” at the mouse location
by Anonymous Monk on Mar 04, 2012 at 09:07 UTC |