Simplified code to show the problem:
my $mw = MainWindow->new;
my $label = $mw->Label(-text => 'Hello', -class => 'Class1')->pack;
$label->configure(-class => 'Class2');
MainLoop;
.Xresources file:
classfunny*Class1.foreground: green
classfunny*Class2.foreground: red
Without the configure statement the program runs as expected. With the statement the label shrinks to almost nothing and shows nothing. On buttons the button text vanishes after the configure. Changing text with configure works fine, so why is changing the class causing a problem.
The class of a widget can't be changed. There is no configure option -class
for Tk widgets after creation.
Unfortunately your attempt to configure -class
does not throw an error, which is a bug. If you add another config option to the configure call like so:
$label->configure(-bg=>'white',-class=>'Class2');
Tk warns unknown option "-class" at test.pl line 9.