#!/usr/bin/perl use strict;
use warnings;
use Tk;
use Tk::FileSelect;
my $main_window = Tk::MainWindow->new;
# --- Source File Frame ---
my $frame_source_file = $main_window->Frame();
my $label_source_file = $frame_source_file->Label();
$label_source_file->configure(-text => 'Source:');
$label_source_file->pack(-side => 'left');
my $entry_source_file = $frame_source_file->Entry();
$entry_source_file->pack(-side => 'left', -expand => 1, -fill => 'x');
my $button_source_file = $frame_source_file->Button();
$button_source_file->configure(-text => 'Browse...');
$button_source_file->pack(-side => 'left');
$frame_source_file->pack(-expand => 1, -fill => 'x');
# --- Target File Frame ---
my $frame_target_file = $main_window->Frame();
my $label_target_file = $frame_target_file->Label();
$label_target_file->configure(-text => 'Target:');
$label_target_file->pack(-side => 'left');
my $entry_target_file = $frame_target_file->Entry();
$entry_target_file->pack(-side => 'left', -expand => 1, -fill => 'x');
my $button_target_file = $frame_target_file->Button();
$button_target_file->configure(-text => 'Browse...');
$button_target_file->pack(-side => 'left');
$frame_target_file->pack(-expand => 1, -fill => 'x');
# --- Frame Action Buttons ---
my $frame_action_buttons = $main_window->Frame();
my $button_action_ok = $frame_action_buttons->Button(-text => 'Ok');
$button_action_ok->pack(-side => 'left');
my $button_action_cancel = $frame_action_buttons->Button(-text => 'Cancel');
$button_action_cancel->pack(-side => 'left');
$frame_action_buttons->pack;
# --- Callbacks ---
$button_source_file->configure(-command => [ \&choose_file, $entry_source_file ]);
$button_target_file->configure(-command => [ \&choose_file, $entry_target_file ]);
$button_action_ok->configure(-command => sub { print "Pressed Ok\n"; });
$button_action_cancel->configure(-command => sub { print "Pressed Cancel\n"; });
Tk::MainLoop();
sub choose_file {
my $entry = shift;
if(my $file_path = $entry->FileSelect->Show()) {
$entry->configure(-text => $file_path);
}
}