merrymonk has asked for the wisdom of the Perl Monks concerning the following question:

Earlier this week I asked questions about a resizable directory selection option for Tk.
Given the answers my plan was to use dirSelect initially and then work on the more flexible dirTree example to get exactly what I wanted.
I do want to be able to give an initial directory as a starting point for the directory selection. The CPAN description says “Any other options provided will be passed through to the DirTree widget that displays directories, so be sure they're appropriate (e.g. -width)”. Therefore I thought that I can specify the directory using the –directory option as in the Perl below.
use Tk; use strict "vars"; use Tk::DirSelect; my $initial_dir = "C:\\Temp"; my $mw; $mw = MainWindow->new; my $ds = $mw->DirSelect( -directory => $initial_dir, -width => 100, -height => 25, -background => red ); my $dir = $ds->Show(); print "dir <$dir>\n"; MainLoop;
However, I got the following error message:
“Can't set -directory to `C:\Temp' for Tk::DirSelect=HASH(0x45a18a8): unknown option "-directory" at … a reference to the Configure.pm line 45”
The Perl code at this point is, I have marked the line
sub configure { my $alias = shift; shift if (@_); my ($set,$get,$widget,@args) = @$alias; if (wantarray) { my @results; eval { @results = $widget->$set(@args,@_) }; croak($@) if $@; return @results; } else { my $results; [line 45]eval { $results = $widget->$set(@args,@_) }; croak($@) if $@; return $results; } }
Should I be able to use the –directory option? If so, does this mean I have something basically wrong with my Perl Tk set up?

Replies are listed 'Best First'.
Re: Tk dirSelect -options problem
by choroba (Cardinal) on Apr 20, 2018 at 09:04 UTC
    Just guessing: the documentation shows

    Show([directory], [options])

    Have you tried passing the initial directory as the first argument to Show?

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      An inspired guess as it turns out since that worked as I wanted. Thank you!

      I tried putting more options in Show().
      -width and -height did not seem to have any effect.
      -background => blue made the frame at the bottom with the OK and Cancel buttons turn blue

      It looks like some experimentation is required unless someone can give some more information or point to where this is documented.

        I tried putting more options in Show()

        Please no more guessing :)

        It looks like some experimentation is required unless someone can give some more information or point to where this is documented.

        Use Tk::WidgetDump... Tk::Wm...

Re: Tk dirSelect -options problem
by Anonymous Monk on Apr 20, 2018 at 19:43 UTC

    Should I be able to use the –directory option?

    Documentation says yes, but error message and source code says no, there is a bug in the module documentation/implementation

    The option in actuality is -dir not -directory

      Thank you. I tried that and found that
      1. it did not give an error:
      2. however, it gave the directory where the Perl was stored rather than the directory supplied as the initial one.
        Not unexpected given its a bug :) give the source a read you'll see what I'm saying