how do i - create bindings 'on the fly' 
Author Message
 how do i - create bindings 'on the fly'

I have a loop creating widgets on the fly.  How can I create bindings
to that widget, even though it has no name.  Will the following work?
  $mw->Widget(-options => value)->pack();
     ->bind(<event1>, [sub {action}])
     ->bind(<event2>, [...
     ...

I tried it this way, but I get a problem with the second binding.  Is
there a special way of doing multiple bindings on the fly that I should
k now about?  (Alternatively, it's just my buggy code, oh well)

Thanks, Gen ;)

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Sun, 07 Jul 2002 03:00:00 GMT  
 how do i - create bindings 'on the fly'

Quote:

> I have a loop creating widgets on the fly.  How can I create bindings
> to that widget, even though it has no name.

What's wrong with using a my variable? If you're in a loop, and
declares this variable inside the loop, it will be forgotten anyway
after exiting the loop.

Quote:
>  Will the following
> work?

No, because bind() doesn't return the widget object like pack().

Quote:
>   $mw->Widget(-options => value)->pack();
>      ->bind(<event1>, [sub {action}])
>      ->bind(<event2>, [...
>      ...

> I tried it this way, but I get a problem with the second binding.  Is
> there a special way of doing multiple bindings on the fly that I should
> k now about?  (Alternatively, it's just my buggy code, oh well)

Regards,
        Slaven

--
use Tk;$c=tkinit->Canvas(-he,20)->grid;$x=5;map{s!\n!!g;map{create$c 'line'=>
map{$a=-43+ord;($x+($a>>3)*2=>5+($a&7)*2)}split''}split"!";$x+=12}split/_/=>'K
PI1_+09IPK_K;-OA1_+K!;A__1;Q!7G_1+QK_3CLPI90,_+K!;A_+1!KQ!.N_K+1Q!.F_1+KN.Q__1+
KN._K+1Q!.F_1+KN.Q_+1Q__+1!KQ!.N_1;Q!7G_K3,09Q_+1!K.Q_K+1Q!.F_1+KN.Q_';MainLoop



Sun, 07 Jul 2002 03:00:00 GMT  
 how do i - create bindings 'on the fly'

Quote:
> I have a loop creating widgets on the fly.  How can I create bindings
> to that widget, even though it has no name.  Will the following work?
>   $mw->Widget(-options => value)->pack();
>      ->bind(<event1>, [sub {action}])
>      ->bind(<event2>, [...
>      ...

> I tried it this way, but I get a problem with the second binding.  Is
> there a special way of doing multiple bindings on the fly that I should
> k now about?  (Alternatively, it's just my buggy code, oh well)

while (....condition...)
    {
    my $new_widget = $mw->Widget(....)->pack(.....);
    $new_widget->bind('<Event1>'=>sub{...some code...});
    $new_widget->bind('<Event2>'=>sub{...some other code...});
    ....maybe more bindings ....
    }

This should work, I think.

Ciao, thomas.

----------------------------------------------------
Thomas Schmickl,
Department for zoology
Karl Franzens University Graz, Austria.
----------------------------------------------------
Visit the GPL e:doc-project on http://members.magnet.at/hfbuch/edoc

----------------------------------------------------



Wed, 10 Jul 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Doing a 'chroot' from Perl

2. CGI.pm creates hidden field '.cgifields'

3. Requirements to 'mortal'ise variables created within XS extensions

4. How to create a 'BACK'-Button

5. How to turn 'die' in 'warn' on the fly

6. OT? Fly GIF's

7. FLY...I'm New please Help!

8. What is pseudorandommy @chars=('a'..'z','A'..'Z','0'..'9','_');

9. Can't open SDBM file doing CGI

10. installing perl is the easiest thing I've ever done since learning how to sleep

11. don't know if this can be done.to do with splitting up file names

12. Can't be done??

 

 
Powered by phpBB® Forum Software