use Tk;
use Win32::FileOp;
my $mw = MainWindow -> new;
my $frmWidth = 452;
my $frmHeigt = 50;
my $screenypos = $mw->screenheight();
my $screenxpos = $mw->screenwidth();
$screenxpos = $screenxpos - $frmWidth;
+
+
$screenxpos = $screenxpos/2;
$screenypos = $screenypos - $frmHeigt;
$screenypos = $screenypos/2;
$mw->geometry("${frmWidth}x$frmHeigt+$screenxpos+$screenypos");
$mw->resizable('no', 'no');
$mw->title ("Test");
my $mainFrame = $mw -> Frame -> pack (-side => 'top', -padx => '8', -p
+ady => '10');
$BrowseFrame = $mainFrame -> Frame() -> pack (-side => 'top', -pady =>
+ '5');
$BrowseFrame -> Button (-text => 'Select folder', -command => \&gotoFi
+le, -background => '#ccccff', -activebackground => '#6666ff') -> pack
+ (-side => 'left', -padx => '5');
$BrowseFrame -> Entry (-textvariable => \$filepath, -width => '84', -b
+ackground => '#ccccff') -> pack (-side => 'left', -padx => '2');
$mw->update;
MainLoop;
sub gotoFile {
$filepath = BrowseForFolder ("Choose Directory", CSIDL_DRIVES, BIF
+_RETURNONLYFSDIRS);
$mw->Unbusy;
return 'Cancel' unless($filepath);
return;
}
Thanks
Srikrishnan | [reply] [d/l] |
| [reply] |
I don't have that Tk module installed on my system, but as guess without testing, I would change:
$filepath = BrowseForFolder ("Choose Directory", CSIDL_DRIVES, BIF_RET
+URNONLYFSDIRS);
to
$filepath = $mw->BrowseForFolder ("Choose Directory", CSIDL_DRIVES, BI
+F_RETURNONLYFSDIRS);
| [reply] [d/l] |
#!/usr/bin/env perl
use strict;
use warnings;
use Tk;
my $mw = MainWindow::->new();
$mw->Button(
-text => 'Select directory',
-command => sub {
my $dir = $mw->chooseDirectory();
# Do something with $dir
# You probably want more than this demo test:
if (defined $dir) {
warn "Directory selected: '$dir'\n";
}
else {
warn "No directory selected.\n";
}
},
)->pack();
MainLoop;
I strongly advise that you
-
always use the strict and warnings pragmata; and,
-
use lexical, instead of package, variables.
| [reply] [d/l] [select] |
| [reply] |
"Thanks for your response and alternate suggestion"
You're welcome.
"in my original script i have used strict and warnings. I used to do that always."
If you do that always, that's great;
however, if you don't show it in your code, we don't know.
An SSCCE is supposed to be code that we can run and reproduces your problem.
Had you included those pragmata, your SSCCE would have output something along the lines of:
Global symbol "$BrowseFrame" requires explicit package name ...
Global symbol "$filepath" requires explicit package name ...
Execution ... aborted due to compilation errors.
So, without them, your SSCCE is not representative of your real code;
and with them, your SSCCE cannot be run.
Also, for future reference, the first "S" in SSCCE stands for "Short".
Please exclude code that is not relevant to the problem.
In this case, all of the cosmetic parts (colours, padding, and so on) could have been omitted;
this allows you, and us, to focus on the parts that matter.
And just so you know, I'm not trying to beat you over the head with a rule book.
Helping us to help you will generally result in faster and better responses.
| [reply] [d/l] |