cursor

Documentation for this package can be found at https://core.tcl-lang.org/tklib/doc/trunk/embedded/www/tklib/files/modules/cursor/cursor.html


The cursor package is intended to display all available cursors on the specific platform.


LV Anyone know a way to create multi-colored and/or animated, cursors?

PT 17-Jun-2005: On Windows you can load system cursors for use as the Tk cursor for a given window. Windows supports the use of animated cursors by using .ani files. On WindowsXP the following will load an animated cursor (the arrow's tail wags):

 package require Tk
 . configure -cursor @c:/windows/Cursors/wagtail.ani

MG After looking at the wagtail cursor, and realising Windows had a load of animated cursors in there I hadn't been away of, I wrote a quick-and-dirty script for browsing through them, which I'll share here in case anyone else wants it.

 package require Tk
 set pattern *.ani ;# animated cursors only
 #set pattern *.cur ;# only non-animated cursors
 #set pattern {{*.cur,*.ani}} ;# all cursors
 set list [glob -dir c:/windows/cursors $pattern]
 set x -1
 bind all <Button-1> advance
 bind all <Button-3> advanceBack
 pack [label .l -text "Click to start!"] -side bottom
 pack [frame .f -height 150 -width 150] -side top
 proc advance {} {
   global list x
   incr x
   if { [llength $list] == $x } {
        set x 0
      }
   foreach w [list . .f .l] {
       $w config -cursor @[lindex $list $x]
      }
   .l config -text "[lindex $list $x]\n[expr {$x+1}] of [llength $list]"
 };# advance
 
 proc advanceBack {} {
   global x
   if { $x >= "0" } {
        incr x -1
      }
 
   foreach w [list . .l .f] {
        $w config -cursor {}
      }
   .l config -text "Click to resume..."
 };# advanceBack

Just click to more forwards one (or go back to the start, if you're at the end), and right-click to "pause", and return to the default cursor, {}. (Right-clicking multiple times will backtrack through them, though it won't tell you it's doing so, and won't return to the end, when you go further back than the start.)


MG Feb 9th 2006 I've had an idea for a new (sub)command/option for Tk, but would like to hear other people's opinions on whether it would be useful, and whether it would be possible to implement without too much trouble, before I think about submitting a TIP or anything like that. (If there's a better place for it than this, please feel free to move the suggestion, btw.) I've heard requests come up in a few places to override (and later restore) the cursors for all widgets under a certain toplevel/widget - the most common use being to display the "busy" cursor everywhere in an app while something's being done. Would something like:

  wm cursor $toplevel hand1

be possible, which would set a "hand1" cursor for the $toplevel toplevel, and all widgets under it? And all widgets under it would display that cursor (regardless of their own -cursor setting), until the 'global' cursor (for lack of a better term) was reset with

  wm cursor $toplevel ""

That might not be the best way to do it - perhaps a -globalcursor (or something) option for widgets, which would (for that widget and all it's children) display that cursor instead of the -cursor/default while set, would be better (as it would allow you to do something for just a particular frame).

Any thoughts/comments/criticisms would be greatly appreciated.


See also cursors