Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tk for project

54 views
Skip to first unread message

ultranewb

unread,
May 12, 2012, 4:42:57 PM5/12/12
to
I have a lot of experience with Tcl, none with Tk.

At any rate, I'd like to use Tk (if possible) for the front end for a
particular project. The basic gist is that I need a screen showing
various graphical "components" and I need to be able to manipulate
these components by dragging them around with the mouse to move them,
and also clicking buttons and controls on the components.

I've looked at Tk. It seems that just making a GUI is easy enough and
straightforward (labels, buttons, combo-boxes, text input fields, blah
blah). But what I've described is something more than just a GUI
(need to be able to drag custom made "widgets" around on the screen).

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.

WJG

unread,
May 12, 2012, 6:25:11 PM5/12/12
to
What OS are you looking to develop for?

WJG

ultranewb

unread,
May 12, 2012, 9:54:48 PM5/12/12
to
On May 13, 5:25 am, WJG <wjgiddi...@blueyonder.co.uk> wrote:
> What OS are you looking to develop for?

Cross platform (unix/windows etc) which I thought wasn't much of an
issue for tcl/tk.

tcltk-d

unread,
May 13, 2012, 9:00:25 PM5/13/12
to
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
}

Helmut Giese

unread,
May 15, 2012, 6:13:30 AM5/15/12
to
Hi,
look at the wiki, e.g. http://wiki.tcl.tk/18081, there's lots of
stuff.
HTH
Helmut Giese

ultranewb

unread,
May 16, 2012, 1:43:15 AM5/16/12
to
Thanks everyone - will check it all out.

0 new messages