dynamically creating labentry widgets with a subroutine and getting right textvariable out

dynamically creating labentry widgets with a subroutine and getting right textvariable out

am 17.10.2007 23:37:34 von ben.rogers

Howdy,

I have a few LabEntry widgets that do similar things so I thought I
would create them with a sub and pass params to it. As you can see, I
pass filetypes4bin to the sub and it displays the list of file types
ok. However, when the user edits the entry field --say to add a few
more filetypes to look for--the textvariable is not updated.

1: How do I get the user modified textvariable out of the sub.
2: How do I keep the params I pass from breaking validatecommand.
$_[1] use to work for checking user input, but now of course it's
getting the value of the label param.

thanks,

ben

$filetypes4bin = "gif|jpg|bmp";

createLabEntryForFileTypes($dircleanPanelToolsSub1, "Pipe-separated
list of file types:", $filetypes4bin);

# Parent, title, textvariable.
sub createLabEntryForFileTypes{

my $parentwidget = $_[0];
my $label = $_[1];
my $filetypes = $_[2];

$parentwidget -> LabEntry(
-label => $label,
-labelPack => [ "-side" => "left" ],
-textvariable => $filetypes,
-width => 50,
-background => 'white',
-validate => 'key',
-validatecommand => sub { $_[1] =~ /\w/i },
-invalidcommand => sub { $mw -> bell })
->pack(-side => 'bottom', -pady => 6);
&stdMsg ("Selected filetypes: $filetypes");
return $filetypes;
}


# aardvark!

Re: dynamically creating labentry widgets with a subroutine and gettingright textvariable out

am 18.10.2007 07:18:27 von paduille.4061.mumia.w+nospam

On 10/17/2007 04:37 PM, ben.rogers@gmail.com wrote:
> Howdy,
>
> I have a few LabEntry widgets that do similar things so I thought I
> would create them with a sub and pass params to it. As you can see, I
> pass filetypes4bin to the sub and it displays the list of file types
> ok. However, when the user edits the entry field --say to add a few
> more filetypes to look for--the textvariable is not updated.
>
> 1: How do I get the user modified textvariable out of the sub.
> 2: How do I keep the params I pass from breaking validatecommand.
> $_[1] use to work for checking user input, but now of course it's
> getting the value of the label param.
>
> thanks,
>
> ben
>
> $filetypes4bin = "gif|jpg|bmp";
>
> createLabEntryForFileTypes($dircleanPanelToolsSub1, "Pipe-separated
> list of file types:", $filetypes4bin);
>
> # Parent, title, textvariable.
> sub createLabEntryForFileTypes{
>
> my $parentwidget = $_[0];
> my $label = $_[1];
> my $filetypes = $_[2];
>
> $parentwidget -> LabEntry(
> -label => $label,
> -labelPack => [ "-side" => "left" ],
> -textvariable => $filetypes,
> [...]

Try changing that line to this:

-textvariable => \$_[2],

Note, I don't have Tk::LabEntry installed and can't test your code.

I don't have an answer for the validatecommand question.