#!/usr/bin/env perl use strict; use warnings; use autodie qw{:all}; use Time::HiRes; use Tk; use Tk::LabFrame; print 'Hit enter when ready to make selection: '; (undef) = scalar <>; my $no_selection_msg = 'No item selected'; my $filename = join '.' => Time::HiRes::time, $$, 'tmp'; open my $pre_fork_fh, ">", $filename; print $pre_fork_fh $no_selection_msg; close $pre_fork_fh; my $pid = fork; if ($pid == 0) { my $mw = MainWindow->new; $mw->geometry('200x300+50+50'); my $app_F = $mw->Frame(); $app_F->pack(-padx => 10, -pady => 10, -fill => 'both', -expand => 1); my $command_LF = $app_F->LabFrame( -label => 'Commands', -labelside => 'acrosstop' )->pack(-side => 'bottom', -fill => 'x', -expand => 0); my $selections_LF = $app_F->LabFrame( -label => 'Selections', -labelside => 'acrosstop' )->pack(-side => 'top', -fill => 'both', -expand => 1); my $selections_Lb = $selections_LF->Scrolled(Listbox => -scrollbars => 'osoe', -selectmode => 'single' )->pack(-padx => 5, -pady => 5, -fill => 'both', -expand => 1); $selections_Lb->insert(end => map { "$_ selected" } 'A' .. 'Z'); my $save_B = $command_LF->Button( -text => 'Save Selection', -command => sub { my $selection_index = $selections_Lb->curselection(); my $selection = length $selection_index ? $selections_Lb->get($selection_index) : $no_selection_msg; open my $child_fork_fh, ">", $filename; print $child_fork_fh $selection; close $child_fork_fh; exit; } )->pack(-padx => 5, -pady => 5); MainLoop; exit; } waitpid $pid => 0; open my $post_fork_fh, "<", $filename; my $selection = <$post_fork_fh>; close $post_fork_fh; unlink $filename; print "Selection made: $selection\n";