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

I have a function to which I pass variables from textboxes (created using the TK Modules) to a subroutine (so I have textboxes name $one $two $three, sub Pie) then what i want is for the new subroutine to read the values from these text boxes, so i call sub{Pie($one,$two,$three)}. However, when i try to get the data back, im having problems. I say "my ( $one_array, $two_array, $three_array ) = @_;" Just as i have learned from tutorials! However, when i try to get the data back out, by writing (example, for the variable $one) my $one_val = $one_array->get(); - However, perl is having trouble with this, it gives me an error Tk::Error: wrong # args: should be ".text get index1 ?index2?" - and i dont udnerstand what this means, can anybody help atall ?
the exact code goes...

the function which takes the variables first...


Perl:
--------------------------------------------------------------------------------
sub createAccount { my( $Username_arr, $Name_arr, $Password_arr, $PassCheck_arr, $Email_arr, $Sylabus_arr, $Instrument_arr, $Theory_arr, $Practical_arr ) = @_; my $username = $Username_arr->get; my $name = $Name_arr->get(); my $password = $Password_arr->get(); my $passconfirm = $PassCheck_arr->get(); my $email = $Email_arr->get(); my $syll = $Sylabus_arr->get(); my $inst = $Instrument_arr->get(); my $theory_g = $Theory_arr->get(); my $practical_g = $Practical_arr->get(); my $test = new MainWindow; $test->title( $Username_arr ); $test->geometry("335x160"); } return true;
--------------------------------------------------------------------------------


and the code for the command button...

Perl:
--------------------------------------------------------------------------------

my $CreateUser = $CreateAcct->Button( -text => "Create Account", -command => sub{createAccount($txtNewUName,$txtNewName,$txtNe +wPassword,$txtNewCPassword,$txtNewEmail,$ListNewSyl l,$ListNewInst,$txtNewTheory,$txtNewPractical)} )->pack;
--------------------------------------------------------------------------------

sorry for any formatting problems :P

thanks!

Edited 2004-02-23 by Ovid -- Added code tags. Did not change other formatting other than to remove an errant left square bracket.

Replies are listed 'Best First'.
Re: Perl TK Problem!
by Grygonos (Chaplain) on Feb 23, 2004 at 20:12 UTC

    Here is the syntax to grab a whole line from a textbox. There are two parameters, start & end.     my $value = $field->get('1.0','1.0 lineend');. The first number , in this case, 1 specifies the line index, then 0 specifies the index in the line. lineend is a modifier that adjust the index to the end of the line. So in my case I simply asjust 1.0 to lineend

    You can find lots of useful info about Tk @ Tk-Tutorial @ Cornell It may not be the most comprehensive or useful documentation list, but I'm rather fond of it.

    Hope that helps,

    Grygonos
      heya, thank you so much, it all works that to them parameters for get() :) Thanks also for the tutorial link (ive been trying to find a good one) and to everyone else who replied (except the first dude! :P)
Re: Perl TK Problem!
by zentara (Cardinal) on Feb 24, 2004 at 15:20 UTC
    I can't say for sure that this is your problem, but it's the first thing that pops out when I look at your code.

    The syntax for passing subroutine parameters in Tk is slightly different form the standard Perl method.

    Try removing the () fromm the params, and separate them with commas. Like:

    sub{[&createAccount,$txtNewUName,$txtNewName,$txtNewPassword]}
    To check what is getting thru, print @_ in your sub. Like:
    sub createAccount { my @in = @_; print Dumper(@_); my( $Username_arr, $Name_arr, $Password_arr, $PassCheck_arr, .... ..... ..... }
    You should start to see what is going on.

    I'm not really a human, but I play one on earth. flash japh
A reply falls below the community's threshold of quality. You may see it by logging in.