| |||||||||||
| |||||||||||
Tktable - Laying out data in a matrix - Tcl/Tk
There's a very common requirement to tabulate data within a GUI, but neither Java (in awt) or Tcl (in Tk) had the facility built in from "day 1". In Java, you now have Jtable within Swing ([example]) and in Tcl you can use a Tktable.
Although Tktable isn't part of standard Tk, you'll find it as a part of most distributions these days, and if it's not in yours, you can download it f.o.c. from Sourceforge. Right - enough of the basics. Here'a an example ![]() Which is displayed from a very simple sample program which we have written - full source code [here] and I then added data within the table as it's interactive. The output produced is as follows when we press the "Save as text" button. earth-wind-and-fire:~/aug07/tkk grahamellis$ wish tktHere are the highlights from that sample program: package require TktableWe load in the Tktable optional package as required array set cells {The cells are populated from a (sparse) array with the element names being row, column pairs table .mytab -rows 14 -cols 8 -variable cellsCreate and pack a tktable widget. Lots of options can be used, but I've just put a minimal few important ones in here to keep the example short and sweet. proc SaveTable {} {The action command when the "Save" button is pressed; it starts off by grabbing the number of rows and columns (which it then loops through) - and the number is slighly awkwardly on the end of a list returned by the configure option on the tktable widget. for {set r 1} {$r < $Rows} {incr r} {This is a "classic" loop going through each row and each column and reading the data from the tktable back. You'll note that I used an info exists to ensure that my program didn't crash when I hit a cell that had not been completed. We cover Tcl programming on our Tcl programming course and then Tk on our Tk Course. Tktable is one of many widgets we introduce you too - there's something of a pattern, so that once I've taught you one, you can learn the others vey easily from the documentation and the knowledge I have imparted. Oh - talking about documentation and further examples, you might like to have a look at a much fuller example published elsewhere (written 2007-08-31 13:26:55) Associated topics are indexed under T246 - Tcl/Tk - Tix Megawidgets
Some other Articles
MySQL joins revisitedWhile waiting for Melksham Post Office Subway Restaurant in Melksham, Wiltshire Oliver says .... Tktable - Laying out data in a matrix - Tcl/Tk GUI design - Sketch it out first! (Java / Swing example) Java - Client side applet applications as well as server side Well House Manor appoints a General Manager Easy handling of errors in PHP Flash - is it available to your web page? 1637 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33 at 50 posts per pageThis is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price. Link to Ezine home page (for reading). Link to Blogging home page (to add comments). |
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho | |||||||||||