As you can see from earlier posts your problem is OS-specific, which is why I couldn't reproduce the problem.
Luckily, I enjoy playing around with Tk, so here's a solution that (I believe) should work on both MSWin and *nix platforms.
This has just one script (pm_1148798_main_tk_with_mod.pl) which uses modules for each of your scripts:
#!/usr/bin/env perl
use warnings;
use strict;
use Tk;
my %script_mod_for = (
Freeze => 'Pm_1148798_freeze_tk_mod',
Dummy => 'Pm_1148798_dummy_tk_mod',
);
my $mw = MainWindow::->new();
$mw->geometry("500x300+50+50");
my $script_F = $mw->Frame->pack(-side => 'bottom', -fill => 'x');
my $button_F = $mw->Frame->pack(-side => 'left', -fill => 'y');
my $text_ST = $mw->Scrolled('Text', -scrollbars => 'se'
)->pack(-expand => 1, -fill => 'both');
my @script_buttons;
push @script_buttons, $button_F->Button(-text => $_, -command => [
\&show_script_gui, $_, $script_mod_for{$_},
$script_F, $text_ST, \@script_buttons
])->pack(-fill => 'x') for keys %script_mod_for;
$button_F->Button(-text => 'Exit', -command => sub { exit }
)->pack(-fill => 'x');
MainLoop;
sub show_script_gui {
my ($script, $mod, $script_F, $text_ST, $script_buttons) = @_;
$text_ST->insert(end => "Running script: $script\n");
eval "require $mod";
$_->configure(-state => 'disabled') for @$script_buttons;
$mod->run($script_F, $text_ST, $script_buttons);
}
Here's the module for your Freeze script (Pm_1148798_freeze_tk_mod.pm).
package Pm_1148798_freeze_tk_mod;
use strict;
use warnings;
require Tk::BrowseEntry;
sub run {
my ($class, $script_F, $text_ST, $script_buttons) = @_;
my ($yyyy, $mmm, $dd) = ('') x 3;
my @years = 2013 .. 2020;
my @months = qw{Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec};
my @days = map { sprintf '%02d', $_ } 1 .. 31;
my $temp_F = $script_F->Frame->pack;
my $done_B;
my %common_be_opts = (
-state => 'readonly', -autolistwidth => '1',
-justify => 'right', -buttontakefocus => 1,
-browsecmd => sub {
$done_B->configure(
-state => $yyyy && $mmm && $dd ? 'normal' : 'disabled'
)
}
);
my %be_pack_opts = (
-ipadx => 15, -side => 'top', -anchor => 'e', -expand => 1
);
my $y_BE = $temp_F->BrowseEntry(%common_be_opts,
-label => 'Select Year', -textvariable => \$yyyy
)->pack(%be_pack_opts);
$y_BE->insert(end => @years);
my $m_BE = $temp_F->BrowseEntry(%common_be_opts,
-label => 'Select Month', -textvariable => \$mmm
)->pack(%be_pack_opts);
$m_BE->insert(end => @months);
my $d_BE = $temp_F->BrowseEntry(%common_be_opts,
-label => 'Select Day', -textvariable => \$dd
)->pack(%be_pack_opts);
$d_BE->insert(end => @days);
$done_B = $temp_F->Button(-text => 'Done', -state => 'disabled',
-command => sub {
$text_ST->insert(end =>
"Selected day: $dd\n" .
"Selected month: $mmm\n" .
"Selected year: $yyyy\n"
);
$temp_F->destroy;
$script_F->configure(-height => 1);
$_->configure(-state => 'normal') for @$script_buttons;
})->pack;
}
1;
And here's a module for a Dummy script (Pm_1148798_dummy_tk_mod.pm).
This is just intended to show that pm_1148798_main_tk_with_mod.pl can handle multiple modules.
package Pm_1148798_dummy_tk_mod;
use strict;
use warnings;
sub run {
my ($class, $script_F, $text_ST, $script_buttons) = @_;
my $temp_F = $script_F->Frame->pack;
$temp_F->Label(-text => 'Dummy Frame for Testing Purposes')->pack;
$temp_F->Button(-text => 'Done', -command => sub {
$temp_F->destroy;
$script_F->configure(-height => 1);
$_->configure(-state => 'normal') for @$script_buttons;
})->pack;
$text_ST->insert(end => "Dummy line 1\n");
$text_ST->insert(end => "Dummy line 2\n");
}
1;
Here's the output from one instance of the script using multiple modules:
Running script: Dummy
Dummy line 1
Dummy line 2
Running script: Freeze
Selected day: 05
Selected month: Jul
Selected year: 2015
Running script: Dummy
Dummy line 1
Dummy line 2
Running script: Dummy
Dummy line 1
Dummy line 2
Running script: Freeze
Selected day: 06
Selected month: Nov
Selected year: 2018
You'll note that once you start either Freeze or Dummy, you must complete it before starting another: those buttons are disabled during a run and only enabled on completion; [Exit] is always enabled so you can quit prematurely if you want.
Also note where I've used use and require. Modules are only loaded on demand.
The overriding intent here was to show the script-module interaction.
I've excluded most of the pretty GUI stuff: colours, borders, etc.
I haven't gone overboard on validation either: currently, you can select 31st February.
Another alternative, similar to your original with two windows, would be Tk::Toplevel (possibly also using Tk::grab).
I'll leave you to investigate this option if you so desire.
Documentation for all widgets (and a few other things, such as geometry managers) are linked from the Tk distro page.
|