G
Go Perl
I am using the following code to create file selection dialogs..But
apparently the Browse buttons do not seem to work.. i got this from
examples provided by typing widget. I changed a little to remove the
radio buttons and stuff, but i am not able to browse and select the
files. I will be glad if anyone can point the error and throw some
light on this.
Thanks very much.
use Tk;
$mw = MainWindow->new();
foreach my $i (qw(one two three four)) {
my $f = $mw->Frame;
my $lab = $f->Label(-text => "Select $i file to Open: ",
-anchor => 'e');
my $ent = $f->Entry(-width => 20);
my $but = $f->Button(-text => "Browse ...",
-command => sub { fileDialog($mw, $ent, $i)});
$lab->pack(-side => 'left');
$ent->pack(-side => 'left',-expand => 'yes', -fill => 'x');
$but->pack(-side => 'left');
$f->pack(-fill => 'x', -padx => '1c', -pady => 3);
}
sub filebox {
my $demo = shift;
(
-name => $demo,
-text => "Enter a file name in the entry box or click on
the \"Browse\" buttons to select a file name
using the file selection dialog.",
-iconname => 'filebox',
);
}
sub fileDialog {
my $w = shift;
my $ent = shift;
my $operation = shift;
my $types;
my $file;
@types =
(["Text files", '*.txt'],
["All files", '*']
);
if ($operation eq 'open') {
$file = $w->getOpenFile(-filetypes => \@types);
}
}
apparently the Browse buttons do not seem to work.. i got this from
examples provided by typing widget. I changed a little to remove the
radio buttons and stuff, but i am not able to browse and select the
files. I will be glad if anyone can point the error and throw some
light on this.
Thanks very much.
use Tk;
$mw = MainWindow->new();
foreach my $i (qw(one two three four)) {
my $f = $mw->Frame;
my $lab = $f->Label(-text => "Select $i file to Open: ",
-anchor => 'e');
my $ent = $f->Entry(-width => 20);
my $but = $f->Button(-text => "Browse ...",
-command => sub { fileDialog($mw, $ent, $i)});
$lab->pack(-side => 'left');
$ent->pack(-side => 'left',-expand => 'yes', -fill => 'x');
$but->pack(-side => 'left');
$f->pack(-fill => 'x', -padx => '1c', -pady => 3);
}
sub filebox {
my $demo = shift;
(
-name => $demo,
-text => "Enter a file name in the entry box or click on
the \"Browse\" buttons to select a file name
using the file selection dialog.",
-iconname => 'filebox',
);
}
sub fileDialog {
my $w = shift;
my $ent = shift;
my $operation = shift;
my $types;
my $file;
@types =
(["Text files", '*.txt'],
["All files", '*']
);
if ($operation eq 'open') {
$file = $w->getOpenFile(-filetypes => \@types);
}
}