I'd like to create a few custom cursors Tkinter (including a magnifying glass).
From reading the documentation I could find, it appears that the only cross-platform way to specify cursors in Tk is using Tk_GetCursorFromData*.
Unfortunately, I can't seem to figure out how to run this from Tkinter. root.tk.call("Tk_GetCursorFromData") fails with invalid command name "Tk_GetCursorFromData". Any suggestions? -- Russell *on unix one can allegedly use "@bitmapfile.xbm" as the cursor specifier, but this is not cross-platform and it didn't even work in my one test on unix.
On my Linux machine, this worked in wish: $ cd /usr/X11R6/include/X11/bitmaps $ wish % . configure -cursor {@cntr_ptr cntr_ptrmsk black white} The Python version would probably read something like import Tkinter t = Tkinter.Tk() t.configure(cursor="@cntr_ptr cntr_ptrmsk black white") t.mainloop() I suspect the 1-arg format "@example.cur" should work just as well on Windows. Tk_GetCursorFromData is a C API, while Tkinter mostly exposes the Tcl API. Reading the Tk_GetCursorFromData manual page, it looks like it doesn't expose any capabilities that the @-form of the cursor property doesn't (instance, the X and Y hotspots are named in the "cntr_ptr" file), but maybe I'm missing something. Jeff
Actually on Windows it gives an exception but you're probably close on the config options. Traceback (most recent call last): File "test-cursor.py", line 3, in ? t.configure(cursor="@cntr_ptr cntr_ptrmsk black white") File "C:\Programs\Python24\Lib\lib-tk\Tkinter.py", line 1139, in configure return self._configure('configure', cnf, kw) File "C:\Programs\Python24\Lib\lib-tk\Tkinter.py", line 1130, in _configure self.tk.call(_flatten((self._w, cmd)) + self._options(cnf)) _tkinter.TclError: bad cursor spec "@cntr_ptr cntr_ptrmsk black white" On Thu, 24 Feb 2005 16:00:21 -0600, Jeff Epler <jepler@unpythonic.net> wrote:
On my Linux machine, this worked in wish: $ cd /usr/X11R6/include/X11/bitmaps $ wish % . configure -cursor {@cntr_ptr cntr_ptrmsk black white}
The Python version would probably read something like import Tkinter t = Tkinter.Tk() t.configure(cursor="@cntr_ptr cntr_ptrmsk black white") t.mainloop() I suspect the 1-arg format "@example.cur" should work just as well on Windows.
Tk_GetCursorFromData is a C API, while Tkinter mostly exposes the Tcl API. Reading the Tk_GetCursorFromData manual page, it looks like it doesn't expose any capabilities that the @-form of the cursor property doesn't (instance, the X and Y hotspots are named in the "cntr_ptr" file), but maybe I'm missing something.
Jeff
_______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org http://mail.python.org/mailman/listinfo/tkinter-discuss
-- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com
On Thu, 24 Feb 2005 16:08:24 -0700 Stewart Midwinter <stewart.midwinter@gmail.com> wrote:
Actually on Windows it gives an exception but you're probably close on the config options.
Traceback (most recent call last): File "test-cursor.py", line 3, in ? t.configure(cursor="@cntr_ptr cntr_ptrmsk black white") File "C:\Programs\Python24\Lib\lib-tk\Tkinter.py", line 1139, in configure return self._configure('configure', cnf, kw) File "C:\Programs\Python24\Lib\lib-tk\Tkinter.py", line 1130, in _configure self.tk.call(_flatten((self._w, cmd)) + self._options(cnf)) _tkinter.TclError: bad cursor spec "@cntr_ptr cntr_ptrmsk black white"
You have to use a tuple instead of a string (at least if you want to use a two-colored cursor), like this: mycursor = ('@/usr/X11R6/include/X11/bitmaps/cntr_ptr', '/usr/X11R6/include/X11/bitmaps/cntr_ptrmsk', 'black', white') t.configure(cursor=mycursor) Michael
In article <20050225115427.04d8ede0.klappnase@web.de>, Michael Lange <klappnase@web.de> wrote:
You have to use a tuple instead of a string (at least if you want to use a two-colored cursor), like this:
mycursor = ('@/usr/X11R6/include/X11/bitmaps/cntr_ptr', '/usr/X11R6/include/X11/bitmaps/cntr_ptrmsk', 'black', white') t.configure(cursor=mycursor)
Thanks everybody for all the help. In summary: - unix, MacOS X and Windows each have a different required file format (the standard format for cursors on that platform). This makes cross-platform cursors in Tkinter a lot of work -- more than I'm ready to do right now. - Unix requirements: - specify an xbm format file path plus at least a foreground color (a fancier form allows a mask and background color as well); - the xbm file must include hotspot info - the multiple args must be in a tuple It is conceivable that if one wrote a C interface to Tk_GetCursorFromData, then one form of data might be acceptable to all platforms. I'm not ready to try that yet. Regards, -- Russell
On Thu, Feb 24, 2005 at 04:08:24PM -0700, Stewart Midwinter wrote:
Actually on Windows it gives an exception but you're probably close on the config options.
The length-4 version is X only. "This form of the command will not work on Macintosh or Windows computers" -- man Tk_GetCursor This is the version that works on Windows: % . configure -cursor @treeview.cur ;# wish, tested or t.configure(cursor="@treeview.cur") # python + tkinter, not tested (treeview.cur is a cursor file that I found in the BLT source directory, but any Windows-format .cur or .ani file is supposed to work) Keep in mind that these filenames are always relative to the working directory, not necessarily to the location of your script or the Python executable. Jeff
participants (4)
-
Jeff Epler -
Michael Lange -
Russell E. Owen -
Stewart Midwinter