For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > September 2004 > Selecting item









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Selecting item
Jan Fure

2004-09-03, 4:01 pm

Hi;

I have written code which uses a textvariable (scalar) for input. The
&search_cells subroutine a matches each item from a list against
$topstructure, and returns the matches as an array @topstructure.

I want to use a Tk widget to select the proper match from a selection
of matches. What is the simplest way in Tk to select one item from a
list which is dynamically defined ( to pick one of the items in
@topstructure)?

I had tried to use a menubutton, but I understand it does not work
because the menu items are defined at program start, and stay static.

I tried to populate the '$menu_topcell' in the &search_cells
subroutine, but I don't know how to first de-populate '$menu_topcell'.

I don't insist on using menubuttons, I would like to hear any
suggested approach for selecting one item from an array which is
dynamically defined/unknown at program start.

If there are many choices, I prefer a way that does not require
additional modules beyond Tk, as I don't have root access on this
system, and it is a long turnaround time for getting new modules.

Jan Fure

My attempt is included below, but doesn't do what I want :-(

$frame6->pack(-expand => 'yes', -fill => 'both', -side => 'top');
$frame6->Entry(-textvariable => \$topstructure, -background => 'red',
-width => '17' )->pack(-side => 'left');
$frame6->Button(-text => "Search", -command => sub{search_cells()},
-activebackground => 'blue', -width => '4' )->pack(-side => 'left');
my $menu_topcell = $frame6->Menubutton(-textvariable =>
\$topstructure, -relief => 'raised', -width => '17')->pack(-side =>
'left');
foreach (@topstructure, 'None') {
$menu_topcell->radiobutton(-label => $_, -variable =>
\$topstructure, -value => $_);
}
Marc Dashevsky

2004-09-03, 4:01 pm

In article <493219b2.0409031016.a70d308@posting.google.com>, list2003@fure.net says...
> Hi;
>
> I have written code which uses a textvariable (scalar) for input. The
> &search_cells subroutine a matches each item from a list against
> $topstructure, and returns the matches as an array @topstructure.
>
> I want to use a Tk widget to select the proper match from a selection
> of matches. What is the simplest way in Tk to select one item from a
> list which is dynamically defined ( to pick one of the items in
> @topstructure)?


Look at Tk::BrowseEntry and Tk::Optionmenu. Both should
do what you wish.

--
Go to http://MarcDashevsky.com to send me e-mail.
Jan Fure

2004-09-09, 3:58 pm

Marc Dashevsky <usenet@MarcDashevsky.com> wrote in message news:<MPG.1ba29078312798ee989a36@netnews.comcast.net>...
> In article <493219b2.0409031016.a70d308@posting.google.com>, list2003@fure.net says...


>
> Look at Tk::BrowseEntry and Tk::Optionmenu. Both should
> do what you wish.


Thanks for the pointers. Tk::BrowseEntry is doing what I want. I
didn't fully understand the documentation:

delete(*index1*, *index2*)
Deletes items from *index1* to *index2*.

By playing around, I realized that the correct usage would look like:
$browse_entry_object->delete($a, $b) where $a and $b are non negative
integers, and $a < $b.

or

$b->delete("0", "10000");

in my particular case, where I want to delete each entry prior to
reconstructing the whole menu.

It is not clear to me what the leading and trailing asterixes in the
documentation for the 'delete' method mean.

Is there a more elegant way to delete all items from a Tk::BrowseEntry
object than just making a really high number for the end of the delete
range?

Jan
Marc Dashevsky

2004-09-09, 3:58 pm

In article <493219b2.0409090855.bc58656@posting.google.com>, list2003@fure.net says...
> Marc Dashevsky <usenet@MarcDashevsky.com> wrote in message news:<MPG.1ba29078312798ee989a36@netnews.comcast.net>...
>
>
> Thanks for the pointers. Tk::BrowseEntry is doing what I want. I
> didn't fully understand the documentation:
>
> delete(*index1*, *index2*)
> Deletes items from *index1* to *index2*.
>
> By playing around, I realized that the correct usage would look like:
> $browse_entry_object->delete($a, $b) where $a and $b are non negative
> integers, and $a < $b.
>
> or
>
> $b->delete("0", "10000");
>
> in my particular case, where I want to delete each entry prior to
> reconstructing the whole menu.
>
> It is not clear to me what the leading and trailing asterixes in the
> documentation for the 'delete' method mean.


My guess is they are an artifact of rendering the pod for display.
On my HTML version of the documentation, the arguments are in bold
face.

> Is there a more elegant way to delete all items from a Tk::BrowseEntry
> object than just making a really high number for the end of the delete
> range?


$b->delete(0, "end");

There is no way you should have known this since you are new to perl/Tk,
but many other widgets use 'end'. BTW, you do not need to quote integer
arguments.

--
Go to http://MarcDashevsky.com to send me e-mail.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com