# test-dir # this is to test the initialdir option for the file browser use strict "vars"; # say to use Tk module use Tk; use Tk::Dialog; my ($mw); my ($sel_dir); my ($add2_entry); my ($dir_full); # create the screen menu # create main window $mw = MainWindow->new; $mw->title("initialdir test"); # button to select the directory $mw->Button(-text => "Select Directory", -command => \&setdir_cb)->gri +d(-row=>0, -column=>0); $mw->Label(-text => "Selected Directory")->grid(-row=>1, -column=>0); $add2_entry = $mw->Entry(-width => 60) ->grid(-row=>1, -column=>1); $dir_full = "No directory selected"; $add2_entry->configure( -textvariable => $dir_full); # button to use the file broswer $mw->Button(-text => "Try File Broswer", -command => \&open_file_brosw +er)->grid(-row=>2, -column=>0); MainLoop; #===================================== # # setdir_cb # # this invokes direcotry selection # #===================================== sub setdir_cb() { my ($err_message, $err_dialog); print "[setdir_cb] entry\n"; $dir_full = $mw->chooseDirectory( ); print "\n\n[setdir_cb] choosen directory <$dir_full>\n"; if(length($dir_full) == 0) { $mw->DialogBox(-title => 'No Directory Selected', -buttons =>['Ok' +], -default_button => 'Ok')->Show(); } else { $add2_entry->configure( -textvariable => $dir_full); $mw->update; } } #===================================== # # open_file_broswer # # this opens the file broswer # #===================================== sub open_file_broswer() { my ($file_selected, $title_str, $answer, $data_file_file_types, $data_ +file_title_str, $file_str); $dir_full = $add2_entry->cget( -textvariable); if(-d $dir_full) { $data_file_title_str = 'Test directory' ; $file_str = 'Data File'; $data_file_file_types = [ [$file_str,'.txt'], ['All files', '*'] ]; $file_selected = $mw->getOpenFile(-initialdir => $dir_full, -filetypes => $data_file_file_types, -title => $data_file_title_str ); } else { $title_str = "Directory <" . $dir_full . '> not found'; $answer = $mw->Dialog(-title => "Directory Not Found", -text => $title_str, -default_button => 'OK', -buttons => [OK], -bitmap => 'error' ) ->Show(); } }
In reply to -initialdir option problemwith getOpenDir (perl tk) by merrymonk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |