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

B

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!
 
M

Mumia W.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top