Tkinter cursor question

G

Gary Richardson

I would like to define a new cursor for use on a Canvas (other than one of
those listed in Appendix F of "Python and Tkinter Programming"). A search on
Google turned up one bit of code that seemed promising. A slightly
simplified version is shown below. This code attempts to eliminate the
cursor by defining an invisible one, which is not what I want, but I thought
it might be a start. However, it doesn't run; the statement t = Text(...)
generates an error message: TclError: bad cursor spec "@testcursor white".
The testcursor file is being created in the current directory.

How can this code be corrected? Where can I find more information on
creating a cursor?

I'm using ActivePython 2.2 Build 224

Thanks,
Gary Richardson
---------------------------
# From a post to c.l.p by Matthew Dixon Cowles on 17 Jul 2002.
from Tkinter import *
import os
kNullCursorData="""
#define t_cur_width 1
#define t_cur_height 1
#define t_cur_x_hot 0
#define t_cur_y_hot 0
static unsigned char t_cur_bits[] = { 0x00};
"""
root=Tk()
os.umask(0177) # octal
fn = "testcursor"
f=open(fn,"w")
f.write(kNullCursorData)
f.close()
t=Text(root,bg="white",cursor="@testcursor white")
t.pack()
root.mainloop()
 
M

Michael Peuser

Gary Richardson said:
I would like to define a new cursor for use on a Canvas (other than one of
those listed in Appendix F of "Python and Tkinter Programming"). A search on
Google turned up one bit of code that seemed promising. A slightly
simplified version is shown below. This code attempts to eliminate the
cursor by defining an invisible one, which is not what I want, but I thought
it might be a start. However, it doesn't run; the statement t = Text(...)
generates an error message: TclError: bad cursor spec "@testcursor white".
The testcursor file is being created in the current directory.


This is rather tricky - you will have to look through Tcl manuals, e.g.:

http://dev.scriptics.com/man/tcl8.3/TkLib/GetCursor.htm


You find there:

@sourceName maskName fgColor bgColor
In this form, sourceName and maskName are the names of files describing
cursors for the cursor's source bits and mask. Each file must be in standard
X11 or X10 cursor format. FgColor and bgColor indicate the colors to use for
the cursor, in any of the forms acceptable to Tk_GetColor. This form of the
command will not work on Macintosh or Windows computers.

@sourceName fgColor
This form is similar to the one above, except that the source is used as
mask also. This means that the cursor's background is transparent. This form
of the command will not work on Macintosh or Windows computers.

@sourceName
This form only works on Windows, and will load a Windows system cursor
(.ani or .cur) from the file specified in sourceName.

Kindly
MichaelP
 
G

Gary Richardson

[snip]
@sourceName
This form only works on Windows, and will load a Windows system cursor
(.ani or .cur) from the file specified in sourceName.

Kindly
MichaelP
Michael,

Thanks for your reply. I am using Windows so I guess I'm out of luck as far
as designing my own cursor. I tried the form that is supposed to work with
windows but no luck with that either. The code below produces the error
message: TclError: bad cursor spec "@CROSS_M.CUR". I also tried using the
full pathname ("@C:\windows\cursors\cross_m.cur" and
"@c:\\windows\\cursors\\CROSS_M.CUR") but the result was the same. Any
further advice?

Thanks,
Gary Richardson
 
M

Michael Peuser

Gary Richardson said:
[snip]
@sourceName
This form only works on Windows, and will load a Windows system cursor
(.ani or .cur) from the file specified in sourceName.
Michael,

Thanks for your reply. I am using Windows so I guess I'm out of luck as far
as designing my own cursor. I tried the form that is supposed to work with
windows but no luck with that either. The code below produces the error
message: TclError: bad cursor spec "@CROSS_M.CUR". I also tried using the

Gary,
seems it totally ignores the leading @ - always looking for a built-in
name....
I used bitmaps some time ago (...,bitmap='@file',.. ) this worked fine.
According to the Tcl/Tk documentation, .., cursor=... should use the routine
Tk_GetCursor. However this is not available when trying to call Tcl directly
by root.tk.call('Tk_GetCursor',...)

Sorry, no more ideas....
Kindly
MichaelP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top