Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Perl/Tk confusion

by Dandello (Monk)
on Jan 25, 2011 at 00:48 UTC ( [id://884027]=perlquestion: print w/replies, xml ) Need Help??

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

For various reasons, not least of which is I'm running a database creator that times out in Apache (when I already have the timeout set at two thousand seconds) and I figure that running the script from command line makes sense here.

The problem - I've got a nice, simple GUI using Perl/Tk - it doesn't need to be fancy - BUT I'm stumped at how to get the information from the GUI into either a simple data file OR directly into the script that needs to use it.

I've gone through the various Perl/Tk tutorials I can find on the 'net and I haven't seen anything that applies.

#!/usr/bin/perl # $Id: tkform1 $ # $Date: 1.25.11 $ # $HeadURL: adamant.net $ # $Revision: 2011 $ # $Source: /tkform1.pl $ ###################################################################### +############ use strict; use warnings; use Tk; our $VERSION = 1.00; my($model, $DATABASE); my $mw = new MainWindow; my $label = $mw -> Label(-text=>"Population Model Form") -> pack(); my $rdb_1 = $mw -> Radiobutton(-text=>"Model 1", -value=>1, -variable=>\$model)-> pack(); my $rdb_2 = $mw -> Radiobutton(-text=>"Model ", -value=>2,-variable=>\$model)-> pack(); my $lab1 = $mw -> Label(-text=>"Initial #:") -> pack(); my $initial = $mw -> Entry(-width=>5,) -> pack(); my $lab2 = $mw -> Label(-text=>"Copying Error % +/-") -> pack(); my $copyerr = $mw -> Entry(-width=>5,) -> pack(); my $lab3 = $mw -> Label(-text=>"How many Year -> population estimates +do you have?") -> pack(); my $LST = $mw -> Entry(-width=>10) -> pack(); my $button = $mw -> Button(-text => "Submit", -command =>\&exitProgam) -> pack(); MainLoop; sub exitProgam { $mw->messageBox(-message=>"Goodbye"); } #sub data_in{ #open my $DATABASE, '>', 'data_in1.txt' or croak 'data_in1 not written +.'; #print {$DATABASE} qq{$model|$initial|$copyerr|$LST\n} or croak 'unabl +e to print'; #close $DATABASE or croak 'data_in1 not closed.'; #} exit;

$model, $initial, $copyerr, and $LST are the variables the next script needs. Also, when I un-comment 'data_in' and replace 'exitProgram' with 'data_in' in 'my $button', the script and/or errors run by so fast I can't read them (Win XP), so obviously I'm missing something.

Replies are listed 'Best First'.
Re: Perl/Tk confusion
by bluescreen (Friar) on Jan 25, 2011 at 01:59 UTC

    I don't get what you mean with run by so fast I can't read them you mean you can't read them in the GUI or that the file is not in the file system because all that sub does is to write a file there is no showing in the UI not even errors, errors will be printed in the STDERR of the shell calling your program and by shell I mean whatever program (Explorer.EXE) is calling your program.

    Then you seem to be confused between widgets vs. value that an specific widget holds, if you want to pass parameters to a command line you have to read widget's contents before invoking it.

    One thing to be expected if you call an external program is that your UI will be frozen while the external program runs and it will look like the program hung.

      I'm so confused about this conversion I don't even know what questions to ask.

      What I was hoping to do is get the values from the widgets and pass them (either directly or through a file) to another script that can run in the background as long as it needs. I can already do this using Apache, but since the long-running script is going to be run on a different machine, I was hoping to just load Perl on it and not worry about configuring Apache on this other machine.

        Here, try this script. It should get you started.
        #!/usr/bin/perl use warnings; use strict; use Tk; my $MainWindow = MainWindow->new; $MainWindow->title("Data Entry Form"); my $NameOfPerson; # global variable $MainWindow -> Label(-justify => 'left', -text => "Name of person : ") ->pack(-side => 'left',-anchor => 'n'); my $entry = $MainWindow -> Entry(-selectborderwidth => 10) ->pack(-side => 'top',-anchor => 'n'); $entry->bind('<Return>',[\&somesub]); $entry->focus; $MainWindow -> Button(-text => "OK", -command => \&somesub) ->pack(-side => 'bottom',-anchor => 'center'); MainLoop; #your script can continue here after Tk is done while(1){print time."\t$NameOfPerson\n"; sleep 1;} sub somesub { $,="\n"; $NameOfPerson = $entry -> get; print "\nNameOfPerson ->$NameOfPerson\n"; $MainWindow -> destroy; }

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://884027]
Approved by Argel
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-23 22:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found