Version 6 of Drag

Updated 2003-07-21 20:00:03

"Drag" is an action idiom common to several GUI canons, roughly co-ordinate with, say "pan". It most often appears in discussions of drag and drop facilities.

It only takes a few lines of Tk to exhibit dragging. Here's an example Michael Kraus offered in the comp.lang.tcl newsgroup:

  pack [button .b -text "The Button" -command exit]
  wm overrideredirect . 1

  bind .b <1> {
    set iX0 [expr %X-[winfo rootx .b]]
    set iY0 [expr %Y-[winfo rooty .b]]
    set bMoved 0
  }

  bind .b <B1-Motion> {
    wm geometry . +[expr %X-$iX0]+[expr %Y-$iY0]
    set bMoved 1
  }

  bind .b <ButtonRelease-1> {
    if { $bMoved } break
  }

This [describe effect ...]

[Next up: exhibit dragging an item around a canvas. Check with CL if you're in a hurry.]


Category Concept | Category GUI