Hi

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 dashboard
use 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; } }
script that starts with a selection box
#!/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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.