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

i have heard of this forum site from another forum because they don't do perl TK and he said you guys did...

i like the TK. i like making real looking programs and the one im making isn't working plz someone help, here is my script...

--------------------------------------------------------------------------------

Code

--------------------------------------------------------------------------------

use Tk; use strict; my $mw = MainWindow->new; $mw->configure(-title => 'Verify User',-background =>'blue'); $mw->geometry('+100+300'); my $vu_frml = $mw->Frame(-relief=>'groove', -borderwidth => 3, -background =>'blue', )->pack(-side => 'top', -fill => 'x'); my $vu_lb1 = $vu_frml->Label(-text =>'name', -background=>'blue',-foreground=>'white', )->pack(-side=>'left'); my $vu_enl = $vu_frml->Entry(-width =>9, -background =>'white')->pack(-side=>'left',-pady=>3); $mw->Button(( -background=>'blue',-foreground=>'white', -text => 'ok', -command => sub { $mw -> Label('-text' => "hello $vu_lb1" +, '-font' => "fixed", )-> pack; }, ))->pack(-side => 'top', -fill => 'x'); MainLoop;

--------------------------------------------------------------------------------

i want it to say hello, name, when you click on the "ok" botton but i don't know how and i tryed but it says "hello (random numbers)" can someone help or point me in the right direction, thanks

Edit: g0n - code tags & formatting

Replies are listed 'Best First'.
Re: perl tk
by atemon (Chaplain) on Oct 04, 2007 at 06:07 UTC

    With almost all Tk widgets, we have the function get which will return the value of the widget. Now you are entering name to the "Tk::Entry" widget you have ( $vu_enl ). So $vu_enl->get() will give you the actual value entered.

    I am including the fixed code here :)

    use Tk; use strict; my $mw = MainWindow->new; $mw->configure(-title => 'Verify User',-background =>'blue'); $mw->geometry('+100+300'); my $vu_frml = $mw->Frame( -relief => 'groove', -borderwidth => 3, -background =>'blue', ) ->pack(-side => 'top', -fill => 'x'); my $vu_lb1 = $vu_frml->Label( -text =>'name', -background=>'blue', -foreground=>'white', )->pack( -side=>'left' ); my $vu_enl = $vu_frml->Entry( -width =>9, -background =>'white' )->pack( -side=>'left',-pady=>3 ); + $mw->Button(( -background=>'blue', -foreground=>'white', -text => 'ok', -command =>sub { $mw -> Label( '-text' => "hello ".$vu_enl->ge +t(), #### Where I changed '-font' => "fixed", )->pack; }, ))->pack(-side =>'top', -fill => 'x'); MainLoop;
    Almost all documentation you may need (regarding Perl/Tk) is available here.

    Welcome to the Monastery !
    please go through The Perl Monks Guide to the Monastery, Writeup Formatting Tips and How (Not) To Ask A Question. Please format your postings with allowed tags. Unlike other forums, this community is strictly disciplined :)

    Updates:
    Formated code to look better.

    Cheers !

    --VC



    There are three sides to any argument.....
    your side, my side and the right side.

Re: perl tk
by graff (Chancellor) on Oct 04, 2007 at 06:12 UTC
    Here's how you code would look in order to do what I think you are trying to do (and this is how it looks when you put <code> and </code> tags around the script, as described in Writeup Formatting Tips):
    use Tk; use strict; my $mw = MainWindow->new; $mw->configure(-title => 'Verify User',-background =>'blue'); $mw->geometry('+100+300'); my $name = ''; # declare a variable for the value of "name" my $vu_frml = $mw->Frame(-relief=>'groove', -borderwidth => 3, -background =>'blue', )->pack(-side => 'top', -fill => 'x'); my $vu_lb1 = $vu_frml->Label(-text =>'name', -background=>'blue', -foreground=>'white', )->pack(-side=>'left'); # use that "name" variable with this Entry widget: my $vu_enl = $vu_frml->Entry(-width =>9, -textvariable => \$name, -background => white' )->pack(-side=>'left',-pady=>3); $mw->Button( -background=>'blue', -foreground=>'white', -text => 'ok', -command => sub { # use the variable again here: $mw -> Label(-textvariable => \$name, -font => "fixed", )-> pack; }, )->pack(-side => 'top', -fill => 'x'); MainLoop;
    The docs for both Tk::Label and Tk::Entry describe how the "-textvariable" attribute is used. It's very handy.