Perl Tk::FBox and filter argument

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Does anyone know what the file pattern format is for the -filter
argument of the perl tk::fbox module?  The CPAN documentation for the
module says filter is to be documented at a later date.

The following code doesn't crash, however, the fileselector that is
displayed isn't showing any .xls files even though I know they are in
the directory.  And, the "Files of Type" droplist in the fileselector
is greyed out and disabled even though the filter specifies two
choices.  If I remove the -filter argument, the fileselector shows all
files in the directory:

use Tk;
use Tk::FBox;

my $mw = MainWindow->new;
$spreadsheetfilename = $mw->FBox(
-type => "open",
-filter =>[
['Excel Files',['*.xls']],
['All Files','*.*']

I'm running Perl on windows XP.


Re: Perl Tk::FBox and filter argument

Sorry folks,

oops! brackets are out of balance: the code really is (but it still
doesn't work):

$spreadsheetfilename = $mw->FBox(-type => "open",
-filter =>[
['Excel Files',['*.xls']],
['All Files',['*.*']]

Re: Perl Tk::FBox and filter argument

Andy wrote:
Quoted text here. Click to load it
Maybe you want to use the -filetypes option??
-filter takes a glob expression. - or a coderef?
It is used internally, so you can't mix these.

my $spreadsheetfilename = $mw->FBox(
-type => "open",
#-filetypes =>[
#['Excel Files',['*.xls']],
#['All Files','*.*']
-filter => '*.x++'

But why don't you use $mw->getOpenFile()?


use Tk;package Tk::_;@ISA=('Tk::Frame');Tk::Widget->Construct
qw|_|,@?=qw'Just another Perl Hacker';sub Populate{($j)=@_;
main::tkinit->_->$_->_->$_->_->$_->_->$_->update for 'pack';sleep 5;

Re: Perl Tk::FBox and filter argument

you are right!  getOpenFile pops up the native windows file selector.  
Don't know why I didn't use it before...  I tried several different
Perl fileselectors and the fbox one looked closest to windows - I
never got the native windows selector in my experimentation before.

For those using fbox, the -filter function accepts a Perl glob()
function which holds a file mask:

$spreadsheetfilename = $mw->FBox(-type => "open",
-filter =>glob('*.xls'),

I found the missing documentation for fbox's -filter argument:

       -filter => $val
           A filter to restrict the directories and files in the icon
list. If
           specified as a glob pattern, then only files will be
filtered by
           the pattern. If specified as a subroutine, then this
           will be called for every file and directory and should
return a
           true value, if the argument should be accepted for the icon
           The arguments of this subroutine are: FBox widget
reference, base-
           name of file, and directory name.

           The subroutine form of this option is experimental.

thanks for the help,

Site Timeline