A full example rewritten to use strict to rule out typos in variable names, plus shortened according to the DRY principle.
#!/usr/bin/perl use strict; use warnings; use Tk; use Tk::ItemStyle; use Tk::TList; my $mw = Tk::MainWindow->new(); my $tl = $mw->TList->pack; my %TkStyle; my %count; for my $color (qw( Black Red Green Blue )) { $TkStyle{$color} = $mw->ItemStyle('text', -stylename => $color, -foreground => $color, -background => 'Wheat', -selectforeground => 'LightSeaGr +een'); $tl->insert('end', -itemtype => 'text', -text => $color, -style => $TkStyle{$color}); ++$count{ $TkStyle{$color} }; } for my $colour (keys %TkStyle ) { my $style = $TkStyle{$colour}; printf("%10s has count %d (style=$style)\n", $colour, $count{$styl +e}); } MainLoop();
Update: The large Tk application I maintain at work uses ItemStyle, but I've never encountered the bug. I checked the code and it seems the only difference is our application doesn't set the -stylename: And indeed, after commenting out the -stylename line, the hashes are always unique!
Update 2: Reported.
In reply to Re: ItemStyle not returning a unique hash (Updated)
by choroba
in thread ItemStyle not returning a unique hash
by andy4321
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |