Skip to content

Tk::ItemStyle doesn't always create a new style when -stylename is specified #111

@choroba

Description

@choroba

See this question on PerlMonks.

To reproduce:

#!/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,  # <- comment this line out
                                      -foreground       => $color,
                                      -background       => 'Wheat',
                                      -selectforeground => 'LightSeaGreen');
    $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{$style});
}

MainLoop();

Sometimes needs to run several times to misbehave. Comment the indicated line out to get the correct behaviour.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions