Python/Tkinter: Using custom mouse cursors under Windows?

半腔热情 提交于 2020-01-29 09:28:28

问题


Python 2.7/Windows: My understanding is that we can load custom mouse cursors using the cursor='@file.cur' syntax:

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

Here's the traceback I receive:

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"

Is it possible to load custom mouse cursors under Windows using Tkinter, a Tkinter extension, or via a Win32 API call?


回答1:


lbl=Label(root, text="toto", cursor="@toto.cur") works for me on Python 2.6 and Vista. Make sure that the cur file is in the working directory of your script (I have a similar traceback if I try to load a non-existing cursor) and that the file is not corrupted.

As an alternative, here is a list of internal cursors: http://www.tcl.tk/man/tcl8.4/TkCmd/cursors.htm



来源:https://stackoverflow.com/questions/4049612/python-tkinter-using-custom-mouse-cursors-under-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!