Andreas44 has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I am currently trying to design a simple Perl program with Win32::GUI. I have a main window which contains a button leading to a sub window, with an text input field. When the program is started, the first user input is displayed correctly to the console after pushing the submit button. If the sub window is called again in the same season, no new input is being accepted, its always the first input only which is getting displayed. Does anyone know how to solve that problem? Thanks in advance. OS: Win 7 32-Bit, Code used:
use strict; use Win32::GUI(); $| = 1; sub MAIN{ my $main = Win32::GUI::Window->new(-width => 840, -height => 480, +-text => 'Main', -name => 'Main'); $main->AddButton(-width => 130, -height => 60, -text => 'Sub', -po +s => [100,100], -name => 'Sub'); $main->AddButton(-width => 66, -height => 24, -text => 'Exit', -po +s => [750,410], -name => 'Exit'); $main->Show(); Win32::GUI::Dialog(); sub Sub_Click { ADD(); } sub Exit_Click { $main->Hide(); system.exit(0); -1; } sub main_Terminate { $main->Hide(); system.exit(0); -1; } } sub ADD{ my $add = Win32::GUI::Window->new(-width => 840, -height => 480, - +text => 'Add', -name => 'add'); $add->Show(); $add->AddTextfield(-text => 'Input', -width => 360, -height => 130 +, -pos => [100,100], -name => 'input'); $add->AddButton(-width => 130, -height => 60, -text => 'Submit', - +pos => [100,300], -name => 'Submit'); $add->AddButton(-width => 66, -height => 24, -text => "Back", -pos + => [750,410], -name => 'Back2'); Win32::GUI::Dialog(); sub Submit_Click { print $add->input->Text(); $add->Hide(); MAIN(); return 0; } sub Back2_Click { $add->Hide(); MAIN(); -1; } sub add_Terminate{ $add->Hide(); MAIN(); -1; } } MAIN();

Replies are listed 'Best First'.
Re: Win32 GUI - Problem with text input field
by Anonymous Monk on Jun 15, 2014 at 23:11 UTC

    Initial diagnosis and why Win32::GUI is bad :)

    update: yup, my assumption was correct; if you add  use warnings; you will be warned about this Variable "$main" will not stay shared ... Variable "$add" will not stay shared a ...

    update: your code fixed up

    #!/usr/bin/perl -- ## ## ## ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr +-ce -nibc -i=4 -pt=0 "-nsak=*" #!/usr/bin/perl -- use strict; use warnings; use Win32::GUI(); Main( @ARGV ); exit( 0 ); sub Main { my $mainWindow = MainWindow(); warn "Dialog ", $mainWindow->Dialog; return; } sub MainWindow { my $main = Win32::GUI::Window->new( -width => 840, -height => 480, -text => 'Main', ); $main->AddButton( -width => 130, -height => 60, -pos => [ 100, 100 ], -text => 'Sub', -onClick => sub { warn "onClick @_ "; IncrementButtonText( @_ ); AddWindow( @_ ); ## launch another dialog? icky }, ); $main->AddButton( -width => 66, -height => 24, -pos => [ 750, 410 ], -text => 'Exit', -onClick => sub { warn "onClick @_ "; return -1; ## end this mainloop }, ); $main->Show(); return $main; } ## end sub MainWindow sub IncrementButtonText { my( $button ) = @_; my $text = $button->Text; $text =~ s{(\d*)$}{ 1 + ($1?$1:0) }e; $button->Text( $text ); return $button; } sub AddWindow { my $add = Win32::GUI::Window->new( -width => 840, -height => 480, -text => 'Add', -onTerminate => sub { warn "onTerminate @_ "; return 1; ## end this dialog }, ); $add->AddTextfield( -width => 360, -height => 130, -pos => [ 100, 100 ], -text => join( ' ', 'Input', scalar gmtime, scalar localtim +e ), -name => 'input', ); my $endthisdialog = sub { AddEnd( $add, @_ ); undef $add; 0; }; $add->AddButton( -width => 130, -height => 60, -pos => [ 100, 300 ], -text => 'Submit', -onClick => $endthisdialog, ); $add->AddButton( -width => 66, -height => 24, -pos => [ 750, 410 ], -text => "Back", -onClick => $endthisdialog, ); $add->Show(); return $add->Dialog(); } ## end sub AddWindow sub AddEnd { warn "AddEnd @_ "; my( $add, $button ) = @_; print $add->input->Text(), "\n"; return; }

    http://search.cpan.org/~robertmay/Win32-GUI-1.06/docs/GUI/Reference/Options.pod#-onEVENT
    http://search.cpan.org/~robertmay/Win32-GUI-1.06/docs/GUI/Reference/Options.pod#-eventmodel

    more generic win32 tips

      Win32::GUI is a dead end, hasn't been updated in forever

      Sounds like from your post that you have a long list of reasons for not liking Win32::GUI. However, just wanted to point out that it looks like there's been 2 new version releases of Win32::GUI in the past 7 days according to its change log. Of course, that's about 4 months after the date of your post.

      Doubt that this new information will change your opinion about using Win32::GUI, but for those looking for help with Win32::GUI and come across this thread, they probably would appreciate knowing that the module is being actively maintained with fairly recent updates.

        dasgar, first release since the seven years since the last time Win32::GUI was abandoned, even microsoft is not pushing MFC anymore

        Adding compiler fixes, and applying five year old patches isn't exactly what I would call "actively maintained" -- its getting some love and that is a good thing

        Single-platform toolkits just are not appealing ( even KMX knows, he releases IUP )

        but if are making money on Win32::GUI, great :)

      Thank you for your help