Updated 2017-10-22 09:27:56 by anon

Richard Suchenwirth 2004-12-12 - To finish this Sunday evening, here's a tool that displays Tk's built-in cursor names on labels, and changes the cursor shape when you move it over one of them.

I have to admit the shapes look a bit 1980-ish, but some of these may still be useful in the 21st century... :^}

For a neat arrangements in alphabetic columns, the long list is split into several column lists:}

2017-10-22: Online demo at [1]
#!/usr/bin/env tclsh
package require Tk
set cursors {
    X_cursor arrow based_arrow_down based_arrow_up boat bogosity
    bottom_left_corner bottom_right_corner bottom_side bottom_tee
    box_spiral center_ptr circle clock coffee_mug cross cross_reverse
    crosshair diamond_cross dot dotbox double_arrow draft_large draft_small
    draped_box exchange fleur gobbler gumby hand1 hand2 heart icon iron_cross
    left_ptr left_side left_tee leftbutton ll_angle lr_angle man middlebutton
    mouse pencil pirate plus question_arrow right_ptr right_side right_tee
    rightbutton rtl_logo sailboat sb_down_arrow sb_h_double_arrow sb_left_arrow
    sb_right_arrow sb_up_arrow sb_v_double_arrow shuttle sizing spider
    spraycan star target tcross top_left_arrow top_left_corner top_right_corner
    top_side top_tee trek ul_angle umbrella ur_angle watch xterm
}
set ncols 4
for {set i 0} {$i<$ncols} {incr i} {
    lappend cols col$i
}
set nmax [expr {int([llength $cursors]*1./$ncols)}]
foreach col $cols {
    set $col [lrange $cursors 0 $nmax]
    set cursors [lrange $cursors [expr $nmax+1] end]
}
#-- The rest is straightforward - let [grid] figure out the geometry...
label .top -text "Move the cursor over a name to see how it looks" \
    -relief ridge
grid .top -columnspan $ncols -sticky news -ipady 2
for {set i 0} {$i<[llength $col0]} {incr i} {
    set row {}
    foreach col $cols {
        set name [lindex [set $col] $i]
        if {$name eq ""} break
        lappend row .l$name
        label .l$name -text $name -anchor w
        bind .l$name <Enter> [list %W config -cursor $name]
    }
    eval grid $row -sticky we
}

LES Very handy! Can one create their own cursors and have Tk use them? How? - RS: In principle, yes - see http://www.tcl.tk/man/tcl8.4/TkLib/GetCursor.htm (you don't need C coding, just go to the place where @... patterns are described), but it's not platform-independent - on Unix/Linux you can give an XBM file with foreground and optional background color; on Windows you can give .ani or .cur files...

LB But XBM doesn't do colors - those are bitmaps. XPM is the format that permits colors. I don't recall whether one can define color cursors or not within Tk. - RS: man Tk_AllocCursorFromObj says: "

  • @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. - i.e., paint the binary "1" pixels in the specified colors.

I had entirely forgotten that three years ago we had a choice of cursor viewers at cursors ... but the novelty of this page seems to be that columns are alphabetic, at least.