I have created a GUI for users to run a few scripts from. When a button is selected to run a script a selection box is created and then the script continues fine.
The issue is that if the users clicks the mouse on the main GUI by mistake it freezes and that goes into a non responsive mode, until you put focus back on the selection box. (This of course may freak out the users).
The only way that i have got round this so far is to withdraw and then deiconify the mainwindow in the sub call. But this leaves the user with no GUI for a couple of seconds until the selection box appears. (Am I being too fussy).
The reason i call the script from the GUI and don't just use a sub call in the main GUI, is that i have 11 different buttons that all call scripts that have about 800 lines of code which as i am new to Perl it gets a bit confusing. So I find it easier this way.
Scripts below are just a test sample of the scenario. main gui dashboardscript that starts with a selection boxuse warnings; use strict; use Tk ; my $mw = MainWindow->new(); $mw->geometry("500x300+50+50"); my $main_frame = $mw->Frame( -relief => 'ridge')->pack(-side => 'top', + -fill => 'x'); my $left_frame = $main_frame->Frame(-relief => 'ridge')->pack(-side => + 'left', -fill => 'y'); my $right_frame = $main_frame->Scrolled("Text", -scrollbars => 'se') ->pack(-expand => 1, -fill => 'both'); my $button1 = $left_frame->Button(-text => "button 1", -command => [\&run_freeze], -relief => 'ridge')- +>pack(-fill => 'x'); my $Close_button = $left_frame->Button(-text => "Exit", -command => [$mw => 'destroy'], -relief => 'ridge' +)->pack(-fill => 'x'); MainLoop; sub run_freeze { open (freeze_script, '-|', 'G:\\opscripts\freeze.pl') or die "\nUn +able to start freeze.pl\n"; ##$mw->withdraw; my $first_line = "processing freeze ........\n"; $right_frame->delete("1.0", 'end'); $right_frame->insert( 'end', $first_line ); my $freeze_line; while (defined ($freeze_line =<freeze_script>) ) { $right_frame->insert( 'end', $freeze_line ); $right_frame->update(); $right_frame->see('end'); ## $mw -> deiconify; } }
#!/usr/bin/perl use strict; use warnings; use Tk; use Tk::BrowseEntry; my $mw = MainWindow->new(); $mw->geometry("300x200"); my $yyyy; $yyyy="" if(!$yyyy); my $mmm; $mmm="" if(!$mmm); my $dd; $dd="" if(!$dd); my $browseEntryyear = $mw ->BrowseEntry( -label => 'Select year :', -relief => 'ridge', -state => 'readonly', -autolistwidth => '1', -justify => 'right', -buttontakefocus => 1, -textv +ariable => \$yyyy, -relief => 'ridge') -> pack( -ipadx => 15, -side => 'top', -anchor => +'e', -expand => 1); $browseEntryyear -> insert('end', qw(2013 2014 2015 2016 2017 2018 + 2019 2020)); my $browseEntrymonth = $mw ->BrowseEntry( -label => 'Select Month :', -state => 'readonly', -autolistwidth => '1', -justify => 'right', -butto +ntakefocus => 1, -textvariable => \$mmm, -relief => 'ridge') -> pack( -ipadx => 15, -side => 'top', -anchor => +'e', -expand => 1); $browseEntrymonth -> insert('end', qw(Jan Feb Mar Apr May Jun Jul +Aug Sep Oct Nov Dec)); my $browseEntryday = $mw ->BrowseEntry( -label => 'Select Day :', -state => 'readonly', -a +utolistwidth => '1', -justify => 'right', -buttontakefocus => 1, -text +variable => \$dd, -relief => 'ridge') -> pack(-ipadx => 15, -side => 'top', -anchor => ' +e',-expand => 1); $browseEntryday -> insert('end', qw(01 02 03 04 05 06 07 08 09 10 +11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31)); my $but = $mw -> Button(-text => " Enter ", -command =>[$mw => 'destroy'], -relief => 'raised' +, -activebackground => "darkgreen", )->pack(-side => "right",-expand => 1); my $closebutton = $mw->Button(-text => " Quit ", -command => [$mw => 'exit'], -relief => 'raised', +-activebackground => "red", )->pack(-side => "left",-expand => 1); $mw->repeat( 900, sub { if( $yyyy =~ m/\d\d\d\d/ and $mmm =~ m/[A-Z][A-z]*/ and $dd =~ + m/\d\d/ ){ $but->configure( -state => 'normal' ); } else{ $but->configure( -state => 'disabled' ); } } ); MainLoop; print " selected Year = $yyyy\n"; print " selected Month = $mmm\n"; print " selected Day = $dd\n"; # script continues on using varaibles above and display stdout in the +main gui textframe
In reply to Perl tk gui freezes after pop up list is launched. by john.tm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |