ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> activeperl
activeperl
RE: Help Needed : JComboBox and Table (Tk)
by Brian Raven other posts by this author
Feb 25 2004 12:56PM messages near this date
Internet Explorer Settings | Re: (no subject)
Suresh Bhatt wrote:
>  
>  Hi all, I am new to perl Tk and i need help regarding combo box and
>  tables. 1) I need to set the value of the combo box into a variable.
>  for example in the following code ... 
>  #!/usr/bin/perl
>  use Tk;
>  use Tk::JComboBox;
>  my $mw = MainWindow->new();
>  my $jcb = $mw->JComboBox(-relief => 'groove', -popuprelief =>
'groove',
>                          -highlightthickness => 0,
>                          -choices => [qw/Black Blue Green Purple Red
Yellow/], )-> pack;
>  $jcb->setSelected( 'Yellow' );
>  $index = $jcb->getSelectedIndex();
>  print $index;

Try putting the above 2 lines after the next one. Nothing visible
happens, therefore no selection can be made, until MainLoop is called.

>  MainLoop;
>  
>  whenever i select an item from the choices
>  eg. Green, i need to assign ' Green ' to the variable $index. How do
>  i go about the same .... 2) Further how do we refresh the cells in a
>  table on run time. I am able to populate it once, but i need to
>  refresh the cell when ever i get new data automatically. Regards
>  Suresh            

First, please post in plain text rather than html. It makes it easier
for other people to answer your questions if they don't have to reformat
your email first.

Second, you don't have 'use strict;' and 'use warnings;'. Perl can help
you if you ask it.

Such widgets usually make use of a -textvariable option and/or a
callback when a selection is made (-selectcommand in this case);

Widgets sometimes have a method which enables you to do the refresh
(choices in this case), but in general you can call a widgets update
method to ensure that any reconfiguration becomes visible.

See the following script for example:
------------------------------------------------------------------
use strict;
use warnings;

use Tk;
use Tk::JComboBox;

my $index;
my @choices = ([qw/Black Blue Green Purple Red Yellow/],
	       [qw/Bert Fred Jim Harry Sid Nancy/],
	       [qw/Sunday Monday Tuesday Wednesday Thursday Friday
Saturday/]);

my $mw = MainWindow-> new();
my $jcb = $mw-> JComboBox(-relief => 'groove', -popuprelief => 'groove',
			 -highlightthickness =>  0,
			 -choices =>  $choices[0],
			 -textvariable =>  \$index,
			 -selectcommand =>  sub { print "Selected:
$index\n" }
			)-> pack;
my $b = $mw-> Button(-text => "Next Choice",
		    -command =>  sub { my $x = shift @choices;
				      push @choices, $x;
				      $jcb-> choices($choices[0]);
	
$jcb-> setSelected($choices[0]->[0]);
				    })-> pack;
$jcb-> setSelected( 'Yellow' );
MainLoop;
print $index;
------------------------------------------------------------------

HTH

-- 
Brian Raven


-----------------------------------------------------------------------
The information contained in this e-mail is confidential and solely 
for the intended addressee(s). Unauthorised reproduction, disclosure, 
modification, and/or distribution of this email may be unlawful. If you 
have received this email in error, please notify the sender immediately 
and delete it from your system. The views expressed in this message 
do not necessarily reflect those of LIFFE Holdings Plc or any of its subsidiary companies.
-----------------------------------------------------------------------


_______________________________________________
ActivePerl mailing list
ActivePerl@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved