IB2017 has asked for the wisdom of the Perl Monks concerning the following question:
Is it possible to allow a popup in a text widget only if a condition is met, i.e. if a text has been selected? This is the code I have so far, which creates a popup, however, it checks if something has been selected only agter its creation.
use strict; use warnings; use Tk; use Tk::Text; my $mw = tkinit(); my $text = $mw->Text()->pack(); $text->insert('end',"This is my first line\n"); $text->insert('end',"This is my second line\n"); PupupTextWidget($mw, $text); $mw->MainLoop(); sub PupupTextWidget{ my ($mw, $obj) = @_; my $messagePopupSave; if ($^O eq 'MSWin32'){ $messagePopupSave="Do something (ctrl+s)"; }else{ $messagePopupSave="Do something (cmd+s)"; } my $menu = $mw->Menu(-tearoff=>0, -menuitems=>[ [command=>$messagePopupSave, -command=>[sub { my $UserInput=$obj->getSelected; print $UserInput; }, $obj,]], [qw/command Copy/, -command=>['clipboardCopy', $obj,]], ]); $obj->menu($menu); return $obj; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Tk pop-up if condition is met
by jcb (Parson) on Aug 05, 2020 at 22:27 UTC | |
by IB2017 (Pilgrim) on Aug 06, 2020 at 11:45 UTC | |
by jcb (Parson) on Aug 07, 2020 at 01:53 UTC | |
A reply falls below the community's threshold of quality. You may see it by logging in. |