Tkinter cursor question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary Richardson

    Tkinter cursor question

    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 "@testcurso r 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(kNullCu rsorData)
    f.close()
    t=Text(root,bg= "white",cursor= "@testcurso r white")
    t.pack()
    root.mainloop()






  • Michael Peuser

    #2
    Re: Tkinter cursor question


    "Gary Richardson" <garyr@fidalgo. net> schrieb im Newsbeitrag
    news:vmq6a09ffl 4c4@corp.supern ews.com...[color=blue]
    > 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[/color]
    on[color=blue]
    > 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[/color]
    thought[color=blue]
    > it might be a start. However, it doesn't run; the statement t = Text(...)
    > generates an error message: TclError: bad cursor spec "@testcurso r white".
    > The testcursor file is being created in the current directory.[/color]


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




    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


    Comment

    • Gary Richardson

      #3
      Re: Tkinter cursor question

      [snip][color=blue]
      >
      > @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
      >[/color]
      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.C UR". I also tried using the
      full pathname ("@C:\windows\c ursors\cross_m. cur" and
      "@c:\\windows\\ cursors\\CROSS_ M.CUR") but the result was the same. Any
      further advice?

      Thanks,
      Gary Richardson
      -------------
      from Tkinter import *
      root=Tk()
      Text(root,bg="w hite",cursor="@ CROSS_M.CUR").p ack()
      root.mainloop()







      Comment

      • Michael Peuser

        #4
        Re: Tkinter cursor question


        "Gary Richardson" <garyr@fidalgo. net>[color=blue]
        > [snip][color=green]
        > >
        > > @sourceName
        > > This form only works on Windows, and will load a Windows system[/color][/color]
        cursor[color=blue][color=green]
        > > (.ani or .cur) from the file specified in sourceName.
        > >[/color][/color]
        [color=blue]
        > Michael,
        >
        > Thanks for your reply. I am using Windows so I guess I'm out of luck as[/color]
        far[color=blue]
        > 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.C UR". I also tried using the[/color]

        Gary,
        seems it totally ignores the leading @ - always looking for a built-in
        name....
        I used bitmaps some time ago (...,bitmap='@f ile',.. ) 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('T k_GetCursor',.. .)

        Sorry, no more ideas....
        Kindly
        MichaelP


        Comment

        Working...