in reply to [Solved:]Tk getOpenFile doubleClick problem
#!/usr/local/bin/perl -w use strict; use warnings; use Tk; use utf8; use v5.12; my $mw = Tk::MainWindow->new( -title => 'main window', ); #Exit when the escape key is pressed $mw -> bind('<Key-Escape>', sub { exit }); my $frame = $mw->Frame(-borderwidth => 3)->pack( -fill => 'both',); my $btn1 = $frame->Button( -text => 'button', -command => sub { buttonClicked() }, -width => 120, -height => 40, )->pack(-fill => 'both',); $frame->Button( -text => 'file selector', -command => sub { select_file() }, )->pack(-fill => 'both',); $frame->Button( -text => 'exit', -command => sub { exit }, )->pack(-fill => 'both',); MainLoop; sub select_file { breakCheckbuttonBindings(); my $file = $mw->getOpenFile( -title => 'select file', ); $file = File::Spec->canonpath( $file ); $mw->after(25,\&restoreCheckbuttonBindings); return $file; } sub buttonClicked { $mw->messageBox(-message=>"you clicked a button!"); } sub breakCheckbuttonBindings { my @tags = $btn1->bindtags; $btn1->bindtags([@tags[1,0,2,3]]); $btn1->bind('<ButtonPress>'=>sub{Tk->break}); } sub restoreCheckbuttonBindings { my @tags = $btn1->bindtags; $btn1->bindtags([@tags[1,0,2,3]]); $btn1->bind('<ButtonPress>'=>''); }
|
|---|