2012-5-13 5:42:57 UTC+9 ultranewb:
> 1) Is Tk "appropriate" for what I described (the main point being the ability to click and drag things around)?
> 2) If so, what's the general way I need to go about this?
> Again, plenty of resources out there if I just want to build a GUI,
> but this is something different.
> If someone can point me to a direction, that would be great. Thanks.
Yes! Tk is not merely a GUI painter,
but has powerfull event binding ability.
You can easily add drag-capability to your any widget,
by function as below:
bind DragIt <B1-Motion> {DragIt %W %X %Y}
bind DragIt <ButtonPress-1> {DragIt %W 0 0}
# "ww" is any child widget in toplevel "w")
proc DragIt {ww {X {}} {Y {}}} {
set w [winfo toplevel $ww]
if {$X=={}} {
bind $w <<DragIt>> "0 0 $Y"
bindtags $ww [concat [bindtags $ww] DragIt]
return
}
set dx [winfo x $w]
set dy [winfo y $w]
if {$X == 0} {
incr dx -[winfo pointerx .]
incr dy -[winfo pointery .]
bind $w <<DragIt>> "$dx $dy [lindex [bind $w <<DragIt>>] 2]"
raise $w
return
}
set ev {}
foreach {x y ev} [bind $w <<DragIt>>] {break}
if {$ev!={}} {
eval $ev Drag $w $X $Y $x $y
return
}
if {[expr abs($X - $dx)]>80} {return}
if {[expr abs($Y - $dy)]>80} {return}
if {[expr abs($X - $dx)]<3 && [expr abs($Y -$dy)]<3} {return}
if {$Y<0} {set Y 0}
# if {$::macOS && $Y<24} {set Y 24}
# Or more special for X-widow?
wm geometry $w +$X+$Y
}