Perl/TkFAQ-12.7如何改变光标指针的形状和颜色?

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

原文:

12.7. How do I change the cursor/color?

Nick Ing-Simmons mailto:nik@tiuk.ti.com and others posted a series of answers to this type of question. In summary what they said was:

Basically

$mw->configure(-cursor => ... );

Unless you use one of built-in cursors it gets messy.

Here copy of what Tk/demos/color_editor does:

#!/usr/local/bin/perl -w use Tk; my $mw = MainWindow->new; $mw->configure(-cursor => ['@' . Tk->findINC('demos/images/cursor.xbm'), Tk->findINC('demos/images/cursor.mask'), 'red', 'green']); MainLoop;

That says that argument to -cursor is a list of 4 things:

1. . Pathname to bitmap with '@' prepended to say it isn't a built in name (Using findINC to locate file relative to Tk install location.)

2. . Pathname to mask bitmap (no @ required)

3. . Foreground colour

4. . Background colour

! I want to remap it for the MainWindow! and will be using a pixmap.

You won't be using a Pixmap with normal X11. X11 allows *bitmap* with optional mask (another bitmap), and two colours.

The optional nature of the mask means that a simple call with a list reference like:

$mw->configure(-cursor => ['watch', 'red', 'blue']);

should work alright.

You may also obtain the value of the default cursor for a widget using something like ->optionGet.

译文:

12.7 如何改变光标指针的形状和颜色?

Nick Ing-Simmons等人曾经讨论过一系列这类的问题。这里总结一下:

简单的说,就是使用如下方法:

$mw->configure(-cursor => ... );

这里,除非你使用那些内置的鼠标(译者注:比如watch,hand2等等),否则将会比较麻烦。

下面是Tk/demos/color_editor里面的做法:(译者注:但我在我的Tk目录里没有找到……)

#!/usr/local/bin/perl -w

use Tk;

my $mw = MainWindow->new;

$mw->configure(-cursor => ['@' . Tk->findINC('demos/images/cursor.xbm'),

Tk->findINC('demos/images/cursor.mask'),

'red', 'green']);

MainLoop;

这里,传递给-cursor的参数有四个:

1. 指针所使用的位图的路径和文件名,以’@’符号开头,说明这不是一个内置的指针名称(这里使用的findINC来定位Tk安装目录中的文件。)

2. 指针所使用的屏蔽位图的路径和文件名(不需要@符号)

3. 前景色

4. 背景色

!我想用一个pixmap文件来给主窗口自定义指针。

对于通常的X11,你不能使用Pixmap。X11只允许使用bitmap,可以带有可选的屏蔽(另一个bitmap)和两个颜色。

屏蔽位图的可选属性意味着,只简单的使用如下的方法(即不指定屏蔽),也可以。

$mw->configure(-cursor => ['watch', 'red', 'blue']);

我们还可以使用->optionGet方法来获得某个组件所使用的指针的默认值。

(译者注:实在惭愧,我没有使用过自定义的指针,也一时没有查到目前的格式要求。而这里给出的例子,好像不能调试通过……还请哪位知道的朋友,不吝赐教!谢谢!)

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