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

Monks,

Please refer to the code below for an example. I'm running SunOS 5.8 Generic_108528-13 sun4u sparc SUNW,Sun-Blade-100, where perl is ActiveState perl v5.6.1 built for sun4-solaris-thread-multi. Running the code below, the first time I click the button, I get a FileOpen dialog with the initial directory of "/", instead of "/tmp" as requested. The second time I click the button, I get a FileOpen dialog with the initial directory of "/tmp", but, the "Directory" box incorrectly says "/".

I saw some references to this problem at this node, but there was no solution posted. I'd like to repost the same question. Is there something wrong with what I'm doing? Is there a bug in getOpenFile()? Is there another way to achieve the same result?

use Tk; use strict; my $mw = MainWindow->new(); my $b = $mw->Button(-text=>"Click me",-command=>sub{foo()})->pack(); MainLoop; sub foo { my $fname = $mw->getOpenFile(-initialdir=>"/tmp",-title=>"trying"); return unless defined ($fname); print "You've selected $fname\n"; }

Replies are listed 'Best First'.
Re: Tk getOpenFile initialdir problem
by eserte (Deacon) on Jun 02, 2004 at 14:23 UTC
    Which Tk version are you using? The code works as expected with perl5.8.0+Tk800.025 and perl5.8.4+Tk804.027, but older Tk::FBox versions are known to have some problems.
      $Tk::VERSION = '800.023'
        Upgrading will surely help. If you can't upgrade, then you could try to just use Tk/FBox.pm and maybe also Tk/Optionmenu.pm from Tk800.025.