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

Hello esteemed monks,

I have an weird problem with a Perl-Tk app that uses Tk::JComboBox v1.14 widgets. First time when I try changing state from 'disabled' to 'normal' to a JComboBox widget it throws an error like this:

Tk::Error: Can't set -state to `normal' for Tk::JComboBox=HASH(0x84da458): Cannot use undef value for object of type 'color' at /usr/lib/perl5/site_perl/5.10.0/Tk/JComboBox.pm line 1061. ...

But it does set state to normal, and after that, it's working fine and doesn't throw any errors when alternatively clicking on buttons.

I suspect it might be a installation specific error, but it appears on two on my Linux boxes with Perl 5.10.0 on Slackware 12.2 respectively 13.0 (but not on WindowsXP, with same Perl version).

Here is a similar, in behaviour, code using a single widget:

#!/usr/bin/perl use strict; use warnings; use Tk; use Tk::JComboBox; my $mw = MainWindow->new; my $jcb = $mw->JComboBox( # -state => 'disabled', -entrywidth => 15, -choices => [ {-name => 'one', -value => 1}, {-name => 'two', -value => 2}, "three", ], )->pack; my $chstate_n = $mw->Button( -text => 'normal', -command => sub { ch_state_normal(); }, )->pack; my $chstate_d = $mw->Button( -text => 'disable', -command => sub { ch_state_disabled(); }, )->pack; MainLoop; sub ch_state_normal { print " normal\n"; $jcb->configure( -state => 'normal', ); } sub ch_state_disabled { print " disabled\n"; $jcb->configure( -state => 'disabled', ); }

Does anybody else see the same behaviour? Thank you!

Replies are listed 'Best First'.
Re: Tk::JComboBox error: Can't set -state to `normal'
by lamprecht (Friar) on Oct 04, 2009 at 12:11 UTC
    Hi,

    can you try the following patch? (The second change is not related to this issue but seems obvious...)

    Cheers, Christoph

    --- C:\Dokumente und Einstellungen\chris\Desktop\devel\ngre\Tk\JComboB +ox-old.pm Mo Okt 30 05:29:15 2006 +++ C:\Dokumente und Einstellungen\chris\Desktop\devel\ngre\Tk\JComboB +ox.pm So Okt 4 14:05:48 2009 @@ -1030,7 +1030,7 @@ $entry->configure(-background => $bg); } } - if ($fg ne $button->cget('-foreground')) { + if ($fg ne $entry->cget('-foreground')) { $entry->{$SWAP_FG} = $entry->cget('-foreground'); $entry->configure(-foreground => $fg); } @@ -1052,7 +1052,7 @@ $entry->configure(-state => 'normal'); return if $Tk::VERSION >= 804; - my $bg = $entry->{SWAP_BG}; + my $bg = $entry->{$SWAP_BG}; $entry->{$SWAP_BG} = $entry->cget('-background'); $entry->configure(-background => $bg); }
      Yes, it works like a charm. Thank you.
Re: Tk::JComboBox error: Can't set -state to `normal'
by AnomalousMonk (Archbishop) on Oct 04, 2009 at 04:18 UTC
    I see the same error behavior you describe.
    >perl -wMstrict -le "use Win32; print 'Win32 name: ', Win32::GetOSName(); print 'Win32 ver: ', Win32::GetOSVersion(); print 'Perl ver: ', $]; " Win32 name: WinXP/.Net Win32 ver: 5126002007681 Perl ver: 5.010000
    (Strawberry Perl.)
      Thank you for the feedback.