Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: Changing state for gridded Entry?

by cniggeler (Sexton)
on Jun 10, 2023 at 19:26 UTC ( [id://11152735]=note: print w/replies, xml ) Need Help??


in reply to Re: Changing state for gridded Entry?
in thread Changing state for gridded Entry?

Thank you for the information! But, if I make the correction and run the code, I get a result of "normal", yet as you can see near the bottom in the call to create the widget, the state is set to "disabled"! And the fact I can't click in the textbox to change the 55 means to me it is indeed in the disabled state...

Further, the toggle button does not toggle between normal and disabled, so apparently $test1 -> Entry is not the "right" Entry... ?

  • Comment on Re^2: Changing state for gridded Entry?

Replies are listed 'Best First'.
Re^3: Changing state for gridded Entry?
by NetWallah (Canon) on Jun 10, 2023 at 20:57 UTC
    Fixed your code:
    use strict; use warnings; use Tk; my $test1; my $var = "55"; my $mw = MainWindow->new(); my $FrameOpt = $mw -> Frame; my $exit_b = $mw->Button(-text => 'Exit', -command => sub { exit })->pack; $mw->Button(-text => "Toggle Textbox", -command => sub { my ($entry) = grep { $_->class eq "Entry" } $FrameOpt->ch +ildren; $entry-> configure(-state => $entry->cget('-state') eq "d +isabled" ? 'normal' : 'disabled'); })->pack; sub GuiTextEntryLabelOnLeftCreate { my ($frame, %x_args) = @_; my $label; my $text = $x_args{'-text'}; delete $x_args{'-text'}; $label = $frame -> Label ( -text => $text, -foreground => "black" ) -> grid ( $frame -> Entry (%x_args) , -sticky => 'w' , -pady => 2 ); $label; } $test1 = GuiTextEntryLabelOnLeftCreate ( $FrameOpt , -text => "Test value" , -textvariable => \$var , -width => 6, -state => "disabled", -foreground => "gray", ); $FrameOpt->pack; MainLoop();
    Your problem was that $test1 did not have any "Entry" .. the entry is a child of $FrameOpt.

                    "These opinions are my own, though for a small fee they be yours too."

      Thanks for your fix! FYI, this is a 26kLOC perl/Tk GUI, and while I've reviewed potential children of $FrameOpt there's a possibility in the future that there could be a match to an unintended target.

      Is there a way to narrow down the search, or is the $test1 handle useless? For instance, I tried $test1 -> $FrameOpt -> Entry but got an error "Can't locate auto/Tk/Frame=HASH(0x68d3998).al" so that's obviously not the approach.

      It could be there is no solution without a different subroutine call, and I don't mean for you to have to delve into that :-) In which case I would carefully comment.

        Instead of searching for the entry, you could explicitly attach a variable ($entry_1) to it at creation time:
        use strict; use warnings; use Tk; my $test1; my $var = "55"; my $mw = MainWindow->new(); my $FrameOpt = $mw -> Frame; my $exit_b = $mw->Button(-text => 'Exit', -command => sub { exit })->pack; my $entry_1; $mw->Button(-text => "Toggle Textbox", -command => sub { #my ($entry) = grep { $_->class eq "Entry" } $FrameOpt->c +hildren; $entry_1-> configure(-state => $entry_1->cget('-state') e +q "disabled" ? 'normal' : 'disabled'); })->pack; sub GuiTextEntryLabelOnLeftCreate { my ($frame, %x_args) = @_; my $label; my $text = $x_args{'-text'}; delete $x_args{'-text'}; $label = $frame -> Label ( -text => $text, -foreground => "black" ) -> grid ( $entry_1 = $frame -> Entry (%x_args) , -sticky => 'w' , -pady => 2 ); $label; } $test1 = GuiTextEntryLabelOnLeftCreate ( $FrameOpt , -text => "Test value" , -textvariable => \$var , -width => 6, -state => "disabled", -foreground => "gray", ); $FrameOpt->pack; MainLoop();

                        "These opinions are my own, though for a small fee they be yours too."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11152735]
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-24 04:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found