Username: Password:

Perl/TkFAQ-12.7怎样改变光标指针的形状和颜色?
来源:linux宝库作者:linux宝库 发布时间:2007-09-30 00:00:00


  原文:

  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方法来获得某个组件所使用的指针的默认值。

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

喜欢本文,那就收藏到:

    Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网
相关评论  我也要评论
还没有关于此文章的相关评论!
  • 昵称: (为空则显示guest)
  • 评论分数: ★ ★ ★★★ ★★★★ ★★★★★
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
  • 导航
    赞助商
    文章类别
    订阅