Why is treeview expanding as I type into styled entry field?

Posted by neil on 2013-05-24 08:17

This is my first attempt at using Tkx styles. I've cut down a more complicated GUI into the simplest example of what I am seeing. As you type into the entry box the ttk__style_configure call, which changes the text depending on the value entered, causes the treeview to widen as each character is typed. When it eventually fills the window the latter starts expanding also.

use warnings;
use strict;

use Tkx;

my $value = '123';

my $mw = Tkx::widget->new(".");
$mw->g_wm_title("test");

_frame_1($mw)->g_pack(-anchor => 'w');
_frame_2($mw)->g_pack(-anchor => 'w');

Tkx::MainLoop;

sub _frame_1
{
        my $parent = shift;
       
        my $frame = $parent->new_ttk__frame(-borderwidth => 10);

        my $label = $frame->new_ttk__label(-text => 'Type here :', -state => 'normal');
        $label->g_grid(-row => 0, -column => 0, -sticky => 'w', -padx => 10);
       
        my $entry = $frame->new_ttk__entry(-textvariable => \$value, -width => 20, -state => 'normal');
        $entry->g_grid(-row => 0, -column => 1);
        $entry->configure(-style => "Entry.TEntry"); # so that we can change the foreground colour
        $entry->configure(-validate => 'key');
        $entry->configure(-validatecommand => [\&_test_field_edit, Tkx::Ev('%P')]);
       
        return $frame;
}

sub _frame_2
{
        my $parent = shift;

        my $frame = $parent->new_ttk__frame(-borderwidth => 5);
       
        my $ml = $frame->new_ttk__treeview(-columns => "column1", -selectmode => 'browse', -show => 'headings');
        $ml->g_grid(-row => 0, -column => 0, -sticky=>'nsew', -padx => 0);
       
        return $frame;
}

sub _test_field_edit
{
        my $ret = (shift eq "123") ? 1 : 0;
        # why is the following line causing the window layout to widen as each key is pressed?
        Tkx::ttk__style_configure("Entry.TEntry", -foreground => $ret ? 'black' : 'red');
        return 1;
}