colintu has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to call configure for a widget that is in a different frame to the one the current callback is running from. It doesn't work, I'm getting Tk::Error output. System is Debian Bullseye. code is:
#!/usr/bin/perl use strict; use Tk; use Tk::TFrame; my $con_but_txt = "Connect"; my $online = 0; my $rd_b2; # Set the software version and display it! my $statusmsg = 'Version 0.1'; #------------ my $mw = MainWindow->new; #------------ my $seg2_f = $mw->TFrame(-label => 'Segment 2', -relief => 'groove', -borderwidth => 2); $rd_b2 = $seg2_f->Button(-text => "Read", -state => 'disabled', -comma +nd => [\&read_seg, 2]); $rd_b2->grid(-row => 3, -column => 1, -sticky => "e", -padx => 4); my $ts_e2 = $seg2_f->Text(-wrap => 'word', -width => 50, -height => +6)->grid( -padx => 4, -p +ady => 4, -row => 0, -co +lumn => 3, -sticky => "ns +ew", -rowspan => 4); $seg2_f->grid(-row => 1, -column => 0, -sticky => "nsew",-padx => 2); #------------- my $base_f = $mw->Frame( -relief => 'groove', -borderwidth => 2); my $status = $base_f->Label(-textvariable => \$statusmsg, -borderwidth + => 2, -width => 20, -relief => 'groove')->grid(-row => 1, +-column => 0, -sticky => "w",-padx => 2,-pady => 3); my $conn_b = $base_f->Button(-textvariable => \$con_but_txt, -command +=> \&connect)->grid(-row => 1, -column => 3, -sticky +=> "e"); $base_f->Button(-text => "Exit", -command => sub {exit})->grid(-row => + 1, -column => 4, -sticky => "e" +); $base_f->grid(-row => 2, -column => 0, -sticky => "w",-padx => 2); #------------- #----------------------------------------- sub read_seg { my $cnt; my $inpstr; my ($segnum) = @_; $statusmsg = sprintf("Reading Segment %d", $segnum); $mw->update(); $mw->after(500); $statusmsg = "Online"; $mw->update(); } sub connect { my $cnt; my $inpstr; # Connect / Disconnect # if ($online == 0) { $online = 1; $con_but_txt = "Disconect"; $statusmsg = 'Online'; } else { $online = 0; $con_but_txt = "Connect"; $statusmsg = 'Offline'; } update_buttons(); } # Enable/Disable various buttons # sub update_buttons { if ($online == 0) { # We are Offline # $rd_b2->cofigure(-state => 'disabled'); $mw->$seg2_f->$rd_b2->cofigure(-state => 'disabled'); } else { # We are Online # $rd_b2->cofigure(-state => 'normal'); $mw->$seg2_f->$rd_b2->cofigure(-state => 'normal'); } }
As you can see from update_buttons I've tried just the widget handle and also a chain down from $mw. Both give output like:
Tk::Error: Can't locate auto/Tk/TFrame=HASH(0x55a20d8dde70).al in @INC + (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.32. +1 /usr/local/share/perl/5.32.1 /usr/lib/x86_64-linux-gnu/perl5/5.32 / +usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl-base /usr/lib/x86_64-l +inux-gnu/perl/5.32 /usr/share/perl/5.32 /usr/local/lib/site_perl) at +./test.pl line 91. Carp::croak at /usr/lib/x86_64-linux-gnu/perl-base/Carp.pm line 289 AutoLoader::autoload_sub at /usr/lib/x86_64-linux-gnu/perl-base/AutoL +oader.pm line 54 AutoLoader::AUTOLOAD at /usr/lib/x86_64-linux-gnu/perl-base/AutoLoade +r.pm line 23 main::update_buttons at ./test.pl line 91 main::connect at ./test.pl line 80 Tk callback for .frame.button Tk::__ANON__ at /usr/lib/x86_64-linux-gnu/perl5/5.32/Tk.pm line 251 Tk::Button::butUp at /usr/lib/x86_64-linux-gnu/perl5/5.32/Tk/Button.p +m line 175 <ButtonRelease-1> (command bound to event)
I'm obviously doing something stupid, but it's been 10 years since I wrote any serious Perl and I can't see my mistake. Help please
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: PerlTk using -confiqure across frames
by tybalt89 (Monsignor) on Jul 07, 2024 at 14:21 UTC | |
by colintu (Acolyte) on Jul 07, 2024 at 14:38 UTC | |
by cavac (Prior) on Jul 12, 2024 at 09:53 UTC | |
by colintu (Acolyte) on Jul 07, 2024 at 14:34 UTC |