Python/Tkinter:在Windows上使用自定义鼠标光标?

3 投票
1 回答
5266 浏览
提问于 2025-04-16 06:16

在Python 2.7和Windows系统中,我了解到我们可以用cursor='@file.cur'的方式来加载自定义的鼠标光标:

widget = tkinter.Label( ..., cursor='@help.cur' )

这是我收到的错误信息:

Traceback (most recent call last):
  File "<pyshell#82>", line 1, in <module>
    widget.config( cursor='@help.cur' )
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1202, in configure
    return self._configure('configure', cnf, kw)
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1193, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
TclError: bad cursor spec "@help.cur"

在Windows下,是否可以通过Tkinter、Tkinter的扩展,或者使用Win32 API调用来加载自定义的鼠标光标呢?

1 个回答

5

lbl=Label(root, text="toto", cursor="@toto.cur") 这个代码在我用Python 2.6和Vista系统时可以正常工作。你需要确保这个.cur文件在你脚本的工作目录里(如果我尝试加载一个不存在的光标,就会出现类似的错误信息),而且这个文件不能损坏。

另外,这里有一个内部光标的列表: http://www.tcl.tk/man/tcl8.4/TkCmd/cursors.htm

撰写回答