in reply to ItemStyle not returning a unique hash

I can confirm the bug. It sometimes manifests even with just 2 existing styles. Adding a MainLoop also shows that the styles are overwriting each other, i.e. the items have wrong colours.

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.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Re^2: ItemStyle not returning a unique hash
by andy4321 (Novice) on Apr 08, 2025 at 11:21 UTC

    Thank you for your quick reply.

    I can confirm that removing -stylename does seem to work.

    That is fab :)