Tkinter cursor question

Gary Richardson garyr at fidalgo.net
Sun Sep 21 05:20:10 CEST 2003


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()










More information about the Python-list mailing list