Hi All,
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;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.