Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Graphical Interface

Status
Not open for further replies.

warangalboy

Technical User
Nov 19, 2004
1
US
Hi,

I am new to TCL/TK and I wanted to build a graphical interface using TK widgets.I created main work area but I am unable to figure out how to add widgets to the work area. Can anyone help me please?

Thank You in advance.

Waragalboy
 
The best way to get started, or, at least the way I got started, is to look at the Tk demos that come with the Tcl/Tk installation. You can see the code for all of them, and copy and paste to your heart's content.

Perhaps one of the least immediately friendly aspects is the "pack" geometry; sort of Salvador Dali meets Tetris. Try this. Here's a proc that will produce a nxn grid of frames with the frames named, .1.1, .1.2, ... .3.3:
Code:
proc mkframes {{n 5}} {
	for {set i 1} {$i<=$n} {incr i} {
		pack [frame .$i -borderwidth 2 -relief groove] -side top
		for {set j 1} {$j<=$n} {incr j} {
			pack [frame .$i.$j -borderwidth 4] -side left
		}
	}
}
So you can make a 3x3 grid of frames, for example, with the statement: mkframes 3. So, now you can put labels in .1.1, entries in .1.2, and buttons in .1.3; packing them all to the top:

set w .1.1
pack [label $w.l1 -text "first label"] -side top
pack [label $w.l2 -text "second label"] -side top
# and so on
set w .1.2
pack [entry $w.e1 -textvariable var1] -side top
pack [entry $w.e2 -textvariable var2] -side top
#and so on
set w .1.3
pack [button $w.b1 -text b-1 -command {set var1 "B-1"}] -side top
pack [button $w.b2 -text b-2 -command {set var2 "B-2"}] -side top


you can do whatever you want with .2.n and .3.n

Bob Rashkin
rrashkin@csc.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top