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

Hello, my first post here, and after more than two days trying a lot of things im still without a solution, a few days i started to play with TK, and my problem is, "How can i set a value who came from a variable?

Example:
my $labelproxy = $frameproxy -> Label(-text=>"\nProxy:") -> pack(); my $proxyentry = $frameproxy -> Entry(-width => 23,-textvariable=>\$oi +) -> pack(); my $chkproxyon = $frameproxy -> Radiobutton(-text=>"ON",-selectcolor = +> green, -value=>\$oi, -variable=>\$proxystatus) -> pack(); my $chkproxyoff = $frameproxy -> Radiobutton(-text=>"OFF",-selectcolor + => green, -value=>"semproxy", -variable=>\$proxystatus) -> pack();

Why when i try print the value of -value=>\$oi i recieve "REF(0xa1b46c0)"

I got the same "error" when i tried using "checkbox" values. thanks, and im sorry if this is wrong place to post.

Replies are listed 'Best First'.
Re: TK, seting value of a variable.
by zentara (Cardinal) on Dec 16, 2010 at 12:30 UTC
    You are not showing any code we can run, but does this example clarify it?
    #!/usr/bin/perl use Tk; my $mw = MainWindow->new; my $rb = 'first button'; my $rb1 = $mw->Radiobutton(-text => "Button One", -value => 'button1', -variable => \$rb, -command => [ \&showRB, \$rb ])->pack; my $rb2 = $mw->Radiobutton(-text => "Button Two", -value => 'button2', -variable => \$rb, -command => [ \&showRB, \$rb ])->pack; MainLoop; sub showRB { print "Arg list is @_\n"; my $state_ref = shift; my $state = $$state_ref; $mw->messageBox(-title => 'Status', -type => 'OK', -message => "Status is :$state:."); }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      Thx for your help folks, well my problem is not to get a variable depending on which checkbuttom was chosen, this i can do. My problem is, if the checkbuttom are "on" i need to get the entry variable,add a string to that variable and print it, and if checkbuttom are off the variable stay "blank", I was succeeded using "if" conditional and setting "onvalues", but i wanted to know if theres a way to do that without using "if". Theres main code:
      #!/usr/local/bin/perl use Tk; use LWP::UserAgent; use HTTP::Response; #######main frame####### my $mw = new MainWindow; # Main Window $mw->geometry("600x450"); $mw->minsize(qw(200 200)); $mw->maxsize(qw(200 200)); $mw->title("SQLMAP Guix"); #####widgets positions### my $frame = $mw -> Frame(-relief=>'raised', -borderwidth=>1, ) ->pack(-side=>'top', -fill=>'x'); my $framemethod = $mw -> Frame(-relief=>'raised', -borderwidth=>1, ) ->pack(-side=>'left',-anchor => 'nw'); my $frameproxy = $framemethod -> Frame(-relief=>'raised', -borderwidth=>1, ) ->pack(-side=>'bottom',-anchor => 'nw'); ################BUT Settings##################### my $botaogo = $frame -> Button(-text => 'GO!', -command =>\&botaogo) - +> pack(-side => 'left', -expand => 1); ########Proxy Settings########## my $labelproxy = $frameproxy -> Label(-text=>"\nProxy:") -> pack(); my $proxyentry = $frameproxy -> Entry(-width => 23,-textvariable=>\$pr +oxyurl) -> pack(); my $chk = $frameproxy -> Checkbutton(-text=>"Use Proxy",-selectcolor = +> green, -variable=>\$radioproxy,-onvalue=> "on")-> pack(); $chk -> deselect(); MainLoop; sub botaogo { if (($radioproxy eq 'on' ) && ($proxyurl =~ "http")){ $radioproxy = "--proxy=$proxyurl"; }else{ $radioproxy = undef; } printf "$radioproxy\n"; }
      This works, and it is ok! But how i said, my program has four more functions similar to that,and i imagined if theres other solution instead put alot of "ifs".
        My problem is, if the checkbuttom are "on" i need to get the entry variable,add a string to that variable and print it,

        I think you just want to use the command option of checkbutton, which fires on any state change.

        #!/usr/bin/perl use Tk; #######main frame####### my $mw = new MainWindow; # Main Window $mw->geometry("600x450"); $mw->minsize(qw(200 200)); $mw->maxsize(qw(200 200)); $mw->title("SQLMAP Guix"); #####widgets positions### my $frame = $mw -> Frame(-relief=>'raised', -borderwidth=>1, ) ->pack(-side=>'top', -fill=>'x'); my $framemethod = $mw -> Frame(-relief=>'raised', -borderwidth=>1, ) ->pack(-side=>'left',-anchor => 'nw'); my $frameproxy = $framemethod -> Frame(-relief=>'raised', -borderwidth=>1, ) ->pack(-side=>'bottom',-anchor => 'nw'); ################BUT Settings##################### my $botaogo = $frame -> Button(-text => 'GO!', -command =>\&botaogo) - +> pack(-side => 'left', -expand => 1); ########Proxy Settings########## my $labelproxy = $frameproxy -> Label(-text=>"\nProxy:") -> pack(); my $proxyentry = $frameproxy -> Entry(-width => 23,-textvariable=>\$pr +oxyurl) -> pack(); ################################## my $chk = $frameproxy -> Checkbutton( -text=>"Use Proxy", -selectcolor => green, -variable=>\$radioproxy, -onvalue=> "on", -command => \&cb_call, ################ )-> pack(); ################################### $chk -> deselect(); MainLoop; sub cb_call{ #put whatever logic you need here, to construct your string $proxyurl = time. 'yeehah'; $proxyentry->update; } sub botaogo { if (($radioproxy eq 'on' ) && ($proxyurl =~ "http")){ $radioproxy = "--proxy=$proxyurl"; }else{ $radioproxy = undef; } printf "$radioproxy\n"; }

        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku ................... flash japh
Re: TK, seting value of a variable.
by Anonymous Monk on Dec 15, 2010 at 19:04 UTC
    Hi,

    When you type something into $proxyentry it sets the value in $o1.

    Then somewhere set $proxystatus = $oi and that will set the value of $chkproxyon

    I would have a different variable for $chkproxyoff, unlees you want $chkproxyoff and $chkproxyon to be the same.

    J.C.

      Thx for you help, but i still have the same problem.
      my $labelproxy = $frameproxy -> Label(-text=>"\nProxy:") -> pack(); my $proxyentry = $frameproxy -> Entry(-width => 23,-textvariable=>\$oi +) -> pack(); $proxystatus = $oi; my $chkproxyon = $frameproxy -> Radiobutton(-text=>"ON",-selectcolor = +> green, -value=>\$proxystatus, -variable=>\$radio) -> pack(); my $chkproxyoff = $frameproxy -> Radiobutton(-text=>"OFF",-selectcolor + => green, -value=>"semproxy", -variable=>\$radio) -> pack();
      When i print $radio, choosing "off" its ok, print in screen "semproxy", but when i choose ON, instead print my variable "$proxystatus" i got "REF(0x9e0d730)"

        Maybe you shouldn't use references in settings then? Or opposite, dereference the returned value?

      Sorry $o1 should be $oi