in reply to Re: need a popup gui stdin
in thread need a popup gui stdin

errors on the below line Can't call method "setgrid" on an undefined value at

$lab_pass -> grid(-row=>2,-column=>1);

Replies are listed 'Best First'.
Re^3: need a popup gui stdin
by AnomalousMonk (Archbishop) on May 25, 2012 at 01:12 UTC
    errors on the below line ...
     $lab_pass -> grid(-row=>2,-column=>1);

    This is code from jack123's reply, not zentara's. Try fixing the former code – it can be fixed – and running it; it may throw light on what you need. Or else try zentara's code, with which I have not experimented, but in which I would have more confidence.

      There is something I am missing I believe I have finally got some code to work as far as supplying the gui and text box with submit button and i have verified the input and everything is getting stored to the $text variable. But there is no more processing of teh remainder of the code which if i comment the block out it will process the remainder of teh code but I HAVE to have stdin with a gui. below is my current code after i hit submit there is no more processing of remaining code.

      my $mw = MainWindow->new; my $text; $mw->Label( -text => "Enter password:" )->pack(); $mw->Entry( -textvariable => \$text )->pack(); $mw->Button( -text => "Submit", -command => sub {exit} )->pack(); MainLoop;

        diamondsandperls:
        Remember that  Tk (and, as far as I understand, any GUI) is an event-driven system. Once program execution enters the  MainLoop() function, the only things that count are events:  Button presses, keypresses on the keyboard, mouse movements and button clicks, etc., etc. The keyboard keypresses that would normally be available via  STDIN are  MainLoop events. Keyboard keypresses can go to a  Text widget, an  Entry widget, etc., if the widget is in focus. Otherwise...
        (Update: However, I think (without testingsee subsequent post) it should be possible to capture  STDIN data before the  MainLoop is entered provided the  Tk script is launched from the command line. If it is launched via an icon click, we're back in territory unfamiliar to me.)

        I know how to re-direct  STDOUT and  STDERR so as to make functions like  print() and  printf() output to, e.g., a  Text box. I do not know how to do anything similar with  STDIN and I am not even sure it is meaningful to talk of doing such a thing (Update: from within the  MainLoop)!

        Can you describe in greater detail what it is you hope to accomplish with your program? What is the nature of the data that  STDIN is supposed to provide?

        After playing around a bit, here's an example of  STDIN accessibility both before and after the  MainLoop function. I don't know how kosher this may be. Again, this code is launched from the command line.

        >perl -wMstrict -le "use Tk; ;; my $text; ;; my $mw = MainWindow->new; ;; $mw->Label(-text => 'Enter text: ')->pack(); $mw->Entry(-textvariable => \$text)->pack(); $mw->Button(-text => 'Submit', -command => sub { $mw->destroy } )->pack(); ;; print qq{before MainLoop: enter text: }; my $pre_ml = <STDIN>; chomp $pre_ml; ;; MainLoop; ;; seek STDIN, 0, 2; print qq{after MainLoop: enter more text: }; my $post_ml = <STDIN>; chomp $post_ml; ;; print qq{before MainLoop: '$pre_ml'}; print qq{in MainLoop: '$text'}; print qq{after MainLoop: '$post_ml'}; " before MainLoop: enter text: Before after MainLoop: enter more text: After all before MainLoop: 'Before' in MainLoop: 'hi there' after MainLoop: 'After all'
        there is something I am missing .... after i hit submit there is no more processing of remaining code.

        You must destroy the MainLoop with $mw->destroy for processing to continue.

        $mw->Button( -text => "Submit", #-command => sub {exit} # no good, will exit whole program -command => sub{ $mw->destroy } # good )->pack();
        Now, after $mw->destroy, any code after the MainLoop line will start to run, as I showed in Re: need a popup gui stdin

        You can then take $text, and run any code you want using it.

        However, if you have an external program, which you want to feed $text to on it's STDIN, you have a few choices.

        One is to run system or exec, with $text as an argument. Like this:

        .... Tk code omitted MainLoop; # after running $mw->destroy, the following lines will get processed h +ere, right after the MainLoop line # if you have an external program to feed $text to, try one of these system( "path_to_program $text"); #or exec ( "path_to_program $text"); # if you want to run your program and get ouput use IPC::Open3; my $pid = open3(\*WRITE, \*READ, \*ERROR,"your_command"); if( ! $pid ){ die "$!\n";} #send $text to your_command's STDIN print WRITE "$text\n"; #get the answer from your_command chomp(my $answer = <READ>); print "response = $answer\n"; #get the error from your_command chomp(my $error = <ERROR>); print "error = $error\n";

        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku ................... flash japh