Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl/Tk - appending info to a label or other widget? 1

Status
Not open for further replies.

parkers

Vendor
Oct 21, 2002
157
GB
Hi,

I'm new to Perl/Tk and am having some difficulties writing out information to particular widgets...

here is a code snippet ... and to be honest it is clear to me where I am going wrong however at this stage I am unsure of the syntax to modify...

while (my $val = $sth->fetchrow_array())
{
$label->configure ( -text => $val);
}

... as can be seen from the code, only the last instance of variable, $val is displayed on the label. What I would like is for the label (or some other appropriate widget) to display all results returned by database search.

Any hints or tips is as always(!) appreciated.

Thanks,
SP
 
Code:
my $labelval="";
while (my $val = $sth->fetchrow_array())
    {
    $labelval.=$val."\n";
    $label->configure ( -text => $labelval);
    }

Is this what you meant
--Paul
 
Hi Paul,

Thanks ... thats exactly what I was looking for.

Cheers,
SP

 
... another question to anyone who knows about Tk widgets and event handling ...

I have a Listbox ... currently I need to select an item then press a button to "do something with the selected item".

i.e.
Select Item from List
Press Button -> run subroutine


Is there a way of dynamically using the selected item on a Listbox? i.e. select an item from the list and on selection perform a task.

i.e.
Select Item from List -> run subroutine

Thanks,
SP
 
Is there a .selected, or .index attribute for the list box which can be used to get the value?
along the lines of
Code:
lb.mylistbox(lb.mylistbox.index).text

BTW - I don't know a lot, expecially about Tk ;)
 
Thanks ... you put me in the right direction ... here is how I was able to achieve (if anyone is interested) ...

... simple 'key' bind event handler:

$listbox->bind
( '<ButtonRelease-1>' =>
sub {my $selected=$listbox->curselection();
\&my_sub($selected) if $selected > -1; }
);

# where $listbox is widget
# $selected is index number of listbox item chosen
# obtained from Tk curselection() function
# my_sub interprets value of $selected and 'does # something worthwhile'

Anyway ... I'll say this again ... what a great forum this is ! ... thanks again for the fast help !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top