Perl/TkFAQ-10.6.如何设置绑定

王朝perl·作者佚名  2008-05-18
窄屏简体版  字體: |||超大  

原文:

10.6. How do I add bindings?

On Fri, 15 Sep 95 10:30:56 BST Nick Ing-Simmons <Nick.Ing-Simmons@tiuk.ti.com> writes: Re: Multiple binds to a single widget?**************************************On Thu, 14 Sep 1995 14:57:54 -0400Alain St <astdenis@cmc.doe.CA> writes:!In the tcl/tk doc I have, they say that prepending the script !with '+' appends the new binding to the current one.!!How do I do that in perlTk? !

You cannot do that that way (yet?) - one issue is what it would mean to prepend '+' to a perl/Tk callback :

$widget->bind('<A>','+',[\&subname,$arg]); # did not look right to me

Other issue is that I would need to manage a list-of-callbacks in glue code.

Bind your new command to a new tag:

$widget->bind('Extra',....);

And add Extra to the widgets bindtags:

$widget->bindtags([ref($widget),$widget,'Extra', $widget->toplevel,'all']);

译文:

10.6. 如何设置绑定?

(译者注:这好像是一个邮件回复,不过已经很老了……)

On Fri, 15 Sep 95 10:30:56 BST Nick Ing-Simmons写到:

回复:如何给一个组件设置多个绑定?

*********************************

On Thu, 14 Sep 1995 14:57:54 –0400

Alain St写到:

!在Tcl/Tk中,我知道只要在代码中使用’+’就可以增加新的绑定了。

!那么在Perl/Tk中应该怎么做?

你不能用这样的方法做——一种方法是在Perl/Tk的回应函数前面加上’+’:

$widget -> bind(‘<A>’,’+’,[\&subname,$arg]);

#但是这样不行。

另一种方法就是需要处理一个连串的会应函数的列表。

首先,将你的新功能绑定到一个新的标签上:

$widget -> bind(‘Extra’,…);

然后,把这个标签(Extra)添加到组件的“绑定标签”(bindtags)中:

$widget->bindtags([ref($widget),$widget,'Extra',$widget->toplevel,'all']);

(译者注:以我的理解,这中方法就是可以方便的实现给多个不同的组件设置同一种绑定,或给一个组件设置多个不同的绑定。建议有兴趣的朋友参阅一下手册perldoc Tk::bindtags)

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航