Popup Menu problem while copy and paste..



Hi All,

Here i am creating a popup menu for text widget..It contains
copy ,paste,delete functions..
I am copying & pasting the data in text widget .
After pasting data using popup menu , data is pasting perfectly into
text widget.
After that i am pressing the "DoSomething" button .
but it is not pressing on first click.For Second click its
working.This problem is in only windows but not in linux..
How i have to solve this problem?
Tk version is Tk-804.027.
Any one pls help?

Here i am copying the sample program...

use Tk;
my $mw = MainWindow->new();

my $txt ;

my $entry = $mw->Entry(-textvariable => \$txt, -background=>'white')-
pack();
my $btn = $mw->Button(-text=>'Do Something',-command=>sub {
print "Doing Something bla bla ..\n";
# Doing Something.......
},-activeforeground=>'red')->pack();

$entry->bind("<Button-3>",\&popups);

my $cbm;
MainLoop;

sub copy_data
{

my($m) = @_;

print "Copy Data \n ";
my $cliptxt ;
eval
{
$mw->clipboardClear;
$mw->clipboardAppend($m->get());
};
if($@)
{
print "$@\n";
}
print "$txt Appended to CLIPBOARD\n";

}

sub paste_data
{
my($m) = @_;
print "Past Data \n ";
my $cliptext;
eval
{
$cliptext = $mw->SelectionGet(-selection => "CLIPBOARD");
};

return unless (length($cliptext));

$m->insert('end',$cliptext);

}

sub delete_data
{
my($m) = @_;
$m->delete('sel.first','sel.last') # Remove Selected text
if($m->selectionPresent()); # if Selection Present

}
sub popups
{
my($w) = @_ ;
my $mnu = $mw->Menu(-menuitems => [
["command" =>'Copy' , -command => sub{ &copy_data($w);} ],
'',
["command" => 'Paste' , -command => sub {&paste_data($w) ;} ],
'',
["command" => 'Delete' , -command => sub {&delete_data($w) ;} ],
],-tearoff=>0);
$mnu->Popup(-popover=>'cursor',-popanchor=>"nw");
}

Regards,
Nagandla.
.


Loading