Brian, Many thanks, this seemed to have solved the problem. I typically use strict; but not use warnings which would have helped. It is strange why the g_grid command will work as I coded it originally on buttons, labels, and entry's but not on lists. If you have any idea why that would be I would like to know.
Thanks, Tony -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Brian Raven Sent: Friday, May 22, 2009 3:09 AM To: [email protected] Subject: RE: listbox error From: [email protected] [mailto:[email protected]] On Behalf Of Tony W. Bass Sent: 22 May 2009 01:45 To: [email protected] Subject: listbox error > Hi All, > > Can anyone explain to me why I get the error: > > Can't call method "g_bind" without a package or object reference at C:\scripts\Error Code\listbox_error.pl line > 17. > > Whenever I run the following code. This is put together from a larger program and if you take out the bind > language you get the same basic error on the curselection statement. This is driving me crazy at this point. > Start by putting ';use strict; use warnings;' at the start of your script, and declaring variables in a small a scope as necessary. > use Tkx; > my $mw = Tkx::widget->new("."); > $mw->g_wm_title("Test Program"); > (my $nb = $mw->new_ttk__notebook(-height => 768, -width => 1024))->g_grid(); > testtab1(); > testtab2(); > Tkx::MainLoop(); > sub testtab1 { > $tab1 = $nb->new_ttk__frame(-padding => "10"); > $userbox = $tab1->new_tk__listbox(-height => 20, -listvariable=>\$cnames)->g_grid(-column=>1,-row=>1); I'm not a Tkx expert, but it looks like g_grid doesn't return what you think it does, so you need to split the above. $userbox = $tab1->new_tk__listbox(-height => 20, -listvariable=>\$cnames); $userbox->g_grid(-column=>1,-row=>1); Then you can move on to your next error, which is a bit more obvious :-) > > $userbox->g_bind("<<ListboxSelect>>", sub {GetSecurity()}); > $nb->add($tab1, -text => 'Test Tab', -state=>'hidden'); > } > @countrynames = ("Argentina", "Australia", "Belgium", "Brazil", "Canada", "China", "Denmark", > "Finland", "France", "Greece", "India", "Italy", "Japan", "Mexico", "Netherlands", "Norway", "Spain", > "Sweden", "Switzerland"); > $cnames = ''; foreach $i (@countrynames) {$cnames = $cnames . ' {' . $i . '}';}; > sub GetSecurity { > my $u; > my @idx = $userbox->curselection; > if ($#idx==0) { > $u = $countrynames[$idx[0]]; > } > print "$u\n"; > } HTH -- Brian Raven This e-mail may contain confidential and/or privileged information. If you are not the intended recipient or have received this e-mail in error, please advise the sender immediately by reply e-mail and delete this message and any attachments without retaining a copy. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden. _______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs _______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
