Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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 ( #957787=note: print w/replies, xml ) Need Help??

in reply to How to popup a widget such as “entry” or “label” at the mouse location

To amplify on what AnonymousMonk said about it requiring a Toplevel window to display an arbitrary widget ( other than a Menu ), your best hack is to try and use an overrideredirect window. Here is a simple example, and you will need to work out the details of the enter/leave bindings for your Tree. It helps that bind sends the the calling widget as the first element of @_.
#!/usr/bin/perl use warnings; use Tk; use strict; my $main = new MainWindow; $main->geometry('200x200'); $main->Button(-text=>"click",-command=>sub{ print "Button left click\n"; })->pack; $main->bind('<ButtonPress-3>', \&some_sub); MainLoop; sub some_sub{ print "@_\n"; my $widget = shift; my $x = $widget->pointerx; my $y = $widget->pointery; my $mw_bdw = 2; #mainwindow border width ### Create a Mainwindow ### my $top = new MainWindow(-borderwidth=>$mw_bdw, -relief=>'ridge', -bg => "#0000FF"); $top->geometry("150x100+$x+$y"); # displaying at top left on any resol +ution $top->overrideredirect(1); # Remove window decorations and keep on all + screens ### create a text widget ### my $imstr = "THIS IS A TEST NOTIFICTION LONG ENOUGH TO WRAP"; my $TEXT = $top->Text( -foreground=> 'white', -background=> '#0000FF', -wrap => 'word', -height => 7, -width => 50)->pack; $TEXT->insert('end', "$imstr", ); #$top-> after(5000, \&exitprg); # autoclose in 5000 milisecs $top->bind('<ButtonRelease>',sub{$top->destroy}); #or sub exitprg MainLoop; #### FUNCTIONS #### sub exitprg { my $top = shift; print STDERR "CALLED EXIT\n"; $top-> destroy; # to kill the window and exit from prog } }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh
  • Comment on Re: How to popup a widget such as “entry” or “label” at the mouse location
  • Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://957787]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2016-08-31 08:09 GMT
Find Nodes?
    Voting Booth?
    The best thing I ever won in a lottery was:

    Results (427 votes). Check out past polls.