home *** CD-ROM | disk | FTP | other *** search
/ ftp.pasteur.org/FAQ/ / ftp-pasteur-org-FAQ.zip / FAQ / tcl-faq / tk / part1 next >
Encoding:
Internet Message Format  |  1998-04-29  |  83.1 KB

  1. Path: senator-bedfellow.mit.edu!bloom-beacon.mit.edu!cambridge-news.cygnus.com!cygnus.com!news.sgi.com!cs.uoregon.edu!not-for-mail
  2. From: jhobbs@cs.uoregon.edu (Jeffrey Hobbs)
  3. Newsgroups: comp.lang.tcl,comp.lang.tcl.announce,comp.answers,news.answers
  4. Subject: FAQ: comp.lang.tcl Tk Toolkit Usage Questions And Answers (1/1)
  5. Followup-To: poster
  6. Date: 28 Apr 1998 04:31:02 -0700
  7. Organization: University of Oregon Computer and Information Sciences Dept.
  8. Lines: 2276
  9. Approved: news-answers-request@MIT.EDU
  10. Message-ID: <6i4elm$6po@psychotix.cs.uoregon.edu>
  11. NNTP-Posting-Host: psychotix.cs.uoregon.edu
  12. Xref: senator-bedfellow.mit.edu comp.lang.tcl:80900 comp.lang.tcl.announce:737 comp.answers:31067 news.answers:128766
  13.  
  14. Archive-name: tcl-faq/tk/part1
  15. Maintainer: Jeffrey Hobbs <jeff.hobbs@acm.org>
  16.  
  17. Tk 4+ Usage FAQ (Frequently Asked Questions)
  18.  
  19. An HTML version of this FAQ can be found at http://www.cs.uoregon.edu/research/tcl/faqs/tk/
  20.  
  21. Tk FAQ for Tcl 7.5+ && Tk 4.1+
  22.  
  23. This FAQ will address commonly asked questions about usage of the Tk
  24. Toolkit (version 4.1+).  By providing answers to commonly asked
  25. questions in this document, it is hoped that new users of Tk may suffer
  26. less frustration getting started with Tk, and that readers of
  27. news:comp.lang.tcl may suffer less frustration reading/answering these
  28. questions repeatedly.
  29.  
  30. For Tk 3 related questions, see the Tk 3 Usage FAQ
  31. (http://www.cs.uoregon.edu/research/tcl/faqs/tk/tk3.txt).
  32.  
  33. This FAQ is posted monthly to news:comp.lang.tcl, comp.answers, and
  34. news.answers and can also be obtained from the Tcl FTP archive
  35. (206.109.1.6) (ftp://ftp.neosoft.com/pub/tcl/) in the /pub/tcl/FAQ
  36. directory.
  37.  
  38. For additional information on Tcl as well as pointers to other
  39. documentation and code, see the FAQ maintained by Larry Virden
  40. (mailto:lvirden@cas.org):
  41. FAQ: news:comp.lang.tcl Tcl Introductory FAQ
  42. (http://www.teraform.com/~lvirden/tcl-faq/part1.html)
  43. which resides on the Tcl FTP archive (ftp://ftp.neosoft.com/pub/tcl/)
  44. as /pub/tcl/FAQ/tcl-faq.part0*.
  45.  
  46. For information on usage of the Tcl programming language, see the
  47. posting by Joe Moss (mailto:joe@morton.rain.com):
  48. FAQ: news:comp.lang.tcl Tcl Language Usage FAQ
  49. (http://www.psg.com/~joem/tcl/faq.html)
  50. which resides on the Tcl FTP archive (ftp://ftp.neosoft.com/pub/tcl/)
  51. as /pub/tcl/FAQ/tcl-faq-usage.
  52.  
  53. For additional information about using Tk on Windows, see the posting by
  54. Eric Johnson (mailto:johnsone@camax.com):
  55. FAQ: news:comp.lang.tcl Tk Windows Usage FAQ
  56. (http://www.pconline.com/~erc/tclwin.htm)
  57. which resides on the Tcl FTP archive (ftp://ftp.neosoft.com/pub/tcl/)
  58. as /pub/tcl/FAQ/tk-usage-windows.
  59.  
  60. Comments, suggestions, and contributions to this FAQ are welcomed by
  61. Jeffrey Hobbs (mailto:jeff.hobbs@acm.org).
  62.  
  63. *Legend:*
  64.    +  Emphasized_item
  65.    +  *Stand-out item*
  66.    +  "Quoted item"
  67.    +  'Embedded code' (less than one line)
  68.    +  
  69.  
  70. Multi-line
  71. code body
  72.  
  73. ========================================================================
  74.  
  75.  
  76. Last generated: Tue Apr 28 11:28:24 MEZ 1998 by Jeffrey Hobbs
  77. (http://www.cs.uoregon.edu/~jhobbs/) Tk 4+ Usage FAQ (Frequently Asked
  78. Questions)
  79. An HTML version of this FAQ can be found at
  80. http://www.cs.uoregon.edu/research/tcl/faqs/tk/
  81. Tk FAQ for Tcl 7.5+ && Tk 4.1+
  82. This FAQ will address commonly asked questions about usage of the Tk
  83. Toolkit (version 4.1+).  By providing answers to commonly asked
  84. questions in this document, it is hoped that new users of Tk may suffer
  85. less frustration getting started with Tk, and that readers of
  86. news:comp.lang.tcl may suffer less frustration reading/answering these
  87. questions repeatedly.
  88. For Tk 3 related questions, see the Tk 3 Usage FAQ
  89. (http://www.cs.uoregon.edu/research/tcl/faqs/tk/tk3.txt).
  90. This FAQ is posted monthly to news:comp.lang.tcl, comp.answers, and
  91. news.answers and can also be obtained from the Tcl FTP archive
  92. (206.109.1.6) (ftp://ftp.neosoft.com/pub/tcl/) in the /pub/tcl/FAQ
  93. directory.
  94. For additional information on Tcl as well as pointers to other
  95. documentation and code, see the FAQ maintained by Larry Virden
  96. (mailto:lvirden@cas.org): FAQ: news:comp.lang.tcl Tcl Introductory FAQ
  97. (http://www.teraform.com/~lvirden/tcl-faq/part1.html) which resides on
  98. the Tcl FTP archive (ftp://ftp.neosoft.com/pub/tcl/) as
  99. /pub/tcl/FAQ/tcl-faq.part0*.
  100. For information on usage of the Tcl programming language, see the
  101. posting by Joe Moss (mailto:joe@morton.rain.com): FAQ:
  102. news:comp.lang.tcl Tcl Language Usage FAQ
  103. (http://www.psg.com/~joem/tcl/faq.html) which resides on the Tcl FTP
  104. archive (ftp://ftp.neosoft.com/pub/tcl/) as /pub/tcl/FAQ/tcl-faq-usage.
  105. For additional information about using Tk on Windows, see the posting by
  106. Eric Johnson (mailto:johnsone@camax.com): FAQ: news:comp.lang.tcl Tk
  107. Windows Usage FAQ (http://www.pconline.com/~erc/tclwin.htm) which
  108. resides on the Tcl FTP archive (ftp://ftp.neosoft.com/pub/tcl/) as
  109. /pub/tcl/FAQ/tk-usage-windows.
  110. Comments, suggestions, and contributions to this FAQ are welcomed by
  111. Jeffrey Hobbs (mailto:jeff.hobbs@acm.org).
  112. *Legend:*    +  Emphasized_item    +  *Stand-out item*    +  "Quoted
  113. item"    +  'Embedded code' (less than one line)    +  
  114. Multi-line code body
  115. ========================================================================
  116.  
  117. Here is the list of questions.  You can search for the corresponding
  118. answer by searching for the question number.  For example, searching for
  119. "#3.1." will get you that answer.
  120.  
  121.  
  122. **** Building and Installing Tk et_al on my system ****
  123.  
  124. #1.1. Are there binaries available for my system?
  125. #1.2. How do I get Tcl/Tk to compile/work on my machine?
  126. #1.3. Why does the link step says that some of the functions Tcl needs
  127. are missing when I am trying to build it?
  128. #1.4. How do I add BLT to a Tcl(X)/Tk?
  129. #1.5. How do I create a dynamically loadable library for Tcl/Tk?
  130. #1.6. Where are the '.lib' files for building shared libraries on
  131. Windows?
  132.  
  133. **** Running Tk applications ****
  134.  
  135. #2.1. Where can I get info on porting my Tk3 application to Tk4? to
  136. Tk8?
  137. #2.2. How do I get my wish application to execute on Unix (I just get
  138. a wish prompt!)?
  139. #2.3. How do I run Tcl/Tk scripts by double-clicking on Windows/Mac?
  140. #2.4. How can I get Tk to use 'send' (I get security error messages)?
  141. Does 'send' work on Windows/Mac?
  142. #2.5. How can I ignore send from other applications?
  143. #2.6. Does Tcl/Tk read a resource/startup file?
  144. #2.7. How can I call Tk scripts from a C program?
  145. #2.8. Why does Tk look funny in CDE/VUE?
  146.  
  147. **** Tk application bindings (mouse and keyboard) ****
  148.  
  149. #3.1. How can I change the default class bindings?
  150. #3.2. How can I delete a binding?
  151. #3.3. How can I bind to the arrow keys?
  152. #3.4. How can I get window manager's mouse bindings to work in my Tk
  153. application?
  154. #3.5. How can I add new actions to an existing binding?
  155. #3.6. How do the mouse buttons map when I have less than 3 buttons?
  156.  
  157. **** Tk user interface questions ****
  158.  
  159. #4.1. How can I set X11 resources for a wish application in an
  160. app-defaults file?
  161. #4.2. Can I choose a particular user interface look and feel?
  162.  How do I get native look and feel on Windows/Mac?
  163. #4.3. How can I change the Tk cursor?
  164. #4.4. How can I change the default colors in Tk?
  165. #4.5. How do I specify fonts in Tk?
  166.  
  167. **** Tk window manager interaction questions ****
  168.  
  169. #5.1. How can I get the geometry of my window (I get 1x1+0+0)?
  170. #5.2. How can I raise or lower a window?
  171. #5.3. How can I withdraw/iconify a window?
  172. How can I remap a withdrawn window?
  173. #5.4. How can I use Tk in a subwindow of a non-Tk application?
  174. #5.5. How can I mix interactions between Xt and Tk/Tcl?
  175. #5.6. How can I bind the ResizeRequest event?
  176. #5.7. What is the difference between wm and winfo?
  177. #5.8. How can I prevent my toplevel from being destroyed?
  178. How do I make my toplevel ignore the window manager delete button?
  179. #5.9. How can I prevent my toplevel from being iconified?
  180. #5.10. How can I keep my toplevel on top?
  181. #5.11. Is Tk fully ICCCM compliant?
  182.  
  183. **** Tk 'canvas' widgets questions ****
  184.  
  185. #6.1. How can I get output from a Tk canvas?
  186. #6.2. How can I fill a canvas area which is bounded by lines as
  187. opposed to a shape like a polygon, oval, etc.?
  188. #6.3. How can I raise/lower canvas window objects or draw graphics
  189. onto a window object inside a canvas?
  190. #6.4. How can I detect when the canvas has been resized?
  191. #6.5. How can I use a list of coordinates in a variable to create a
  192. polygon (or any other item)?
  193. #6.6. How can I speed up 'canvas' performance?
  194. #6.7. How can I put/print an image on the 'canvas'?
  195. #6.8. Why doesn't the 'canvas' seem to start at 0,0?
  196. #6.9. Does the 'canvas' have a 'see' method?
  197.  
  198. **** Tk 'entry' widgets questions ****
  199.  
  200. #7.1. How can I initialize an entry widget with some text?
  201. #7.2. How can I limit entry widget input (length or type of chars)?
  202.  
  203. **** Tk 'listbox' widgets questions ****
  204.  
  205. #8.1. How can I select multiple items that are not adjacent in the
  206. listbox at one time?
  207. #8.2. How can I select items in more than one Tk listbox at a time?
  208. #8.3. How can I avoid fractional white space at the end of a resizable
  209. listbox?
  210. #8.4. How can I scroll multiple listboxes with one scrollbar?
  211. #8.5. Why doesn't '.listbox curselection' or 'selection get' return
  212. the proper item when I make a button binding to my listbox?
  213. #8.6. Can I have different colored lines in a listbox?
  214.  
  215. **** Tk 'menu' widget questions ****
  216.  
  217. #9.1. How can I get the tearoff menu to reflect changes in the regular
  218. menu?
  219. #9.2. Why do I have problems accessing item/index 0 of my menu?
  220. #9.3. How do know when I am over a specific entry in a menu?
  221.  
  222. **** Tk 'text' widgets questions ****
  223.  
  224. #10.1. How can I pack a text widget so that it can be resized
  225. interactively?
  226. #10.2. Why do I get an extra newline from the text widget?
  227. #10.3. How can I check to see if the text widget contents have
  228. changed?
  229. #10.4. How can I maintain read-only sections of a text widget?
  230. #10.5. Is there an overwrite/overstrike mode for text/entry widget?
  231. #10.6. How can I always see the end of the text widget?
  232. #10.7. Does the text widget have undo?
  233.  
  234. **** Miscellaneous Tk widget questions ****
  235.  
  236. #11.1. How can I create a scrollable window of buttons?
  237. #11.2. How can I create a widget with an upper case name?
  238. #11.3. How can I vertically align radio/check buttons regardless of
  239. font?
  240. #11.4. How can I group a set of radiobuttons together?
  241.  
  242. **** Tk image questions ****
  243.  
  244. #12.1. Does Tk support JPEG/GIF/XPM/etc?
  245. #12.2. How can I specify bitmap/image patterns on the command line
  246. instead of as a file name?
  247. What is the format of the '-data' option for images?
  248. #12.3. How do I get Tk to recognize the transparency in my GIF images?
  249. #12.4. How can I get bitmaps created with 'image' to work with
  250. '-stipple'?
  251.  
  252. **** Tk geometry manager questions ****
  253.  
  254. #13.1. How can I find my invisible windows when using the packer?
  255. #13.2. How can I get 'cget' to return the correct size of a resized
  256. widget?
  257. ('.widget cget -width|height' returns the wrong size!)
  258. #13.3. How can I add a row/col to the grid?
  259.  
  260. **** Miscellaneous Tk questions ****
  261.  
  262. #14.1. How can I get the name of my own interpreter?
  263. #14.2. How can I destroy every window except '.'?
  264. #14.3. How can I get drag & drop functionality in my program?
  265. #14.4. How can I get a double-click to ignore a single-click?
  266. #14.5. How can I warp the mouse pointer?
  267. #14.6. How do I run wish programs without a display?
  268. How do I run my wish program on a server?
  269. #14.7. Is there a difference between stand-alone Tk and the Tk plugin?
  270. #14.8. How can I do terminal emulation in Tk?
  271.  
  272. **** Questions on Tk related extensions/applications ****
  273.  
  274. #15.1. What is incrTcl/incrTk?
  275. #15.2. What is BLT?
  276. #15.3. What is Tix?
  277. #15.4. Is there a GUI builder available?
  278.  What is SpecTcl/XF/Visual Tcl?
  279. #15.5. Is there a spreadsheet/table widget in Tk?
  280.  What is TkTable?
  281. #15.6. What other languages besides Tcl does Tk work with?
  282.  What is this (Perl|Scheme|Guile|.*)/Tk I've heard about?
  283.  
  284. **** Reporting bugs, Asking further questions, Other resources ****
  285.  
  286. #16.1. My question isn't answered here.  What do I do now?
  287. What is the netiquette for posting to the newsgroup?
  288. #16.2. I think I found a bug in Tk.  How do I go about reporting it?
  289. #16.3. There's a bug in the FAQ.  How do I go about reporting it?
  290. #16.4. What documentation can I find online?
  291.  
  292.  
  293. ***
  294. *** Questions and Answers
  295. ***
  296.  
  297.  
  298. **
  299. * Building and Installing Tk et_al on my system
  300. **
  301.  
  302. #1.1. Are there binaries available for my system?
  303.  
  304. Tcl/Tk binaries are freely available for the Macintosh and Windows
  305. platforms at:
  306.      Windows:    ftp://ftp.sunlabs.com/pub/tcl/win(version).exe     
  307.     Macintosh:    ftp://ftp.sunlabs.com/pub/tcl/mactk(version).sea.hqx
  308.  and mirrored at:
  309.      ftp://ftp.neosoft.com/pub/tcl/mirror/ftp.smli.com/
  310. The binaries are self-extracting archives.  Run the program to install
  311. Tcl/Tk.
  312.  
  313. The sources are freely available from the same places.  You can pay a
  314. nominal fee for precompiled UNIX binaries.  See
  315. http://sunscript.sun.com/TclTkCore/ for more information. See the Tcl
  316. Home Page (http://sunscript.sun.com/) for a listing of the newest
  317. available versions.
  318.  
  319. ========================================================================
  320.  
  321. #1.2. How do I get Tcl/Tk to compile/work on my machine?
  322.  
  323. Look in the Tcl distribution for the file called "porting.notes". This
  324. will contain a collection of notes that various people have provided
  325. about porting Tcl to various machines and operating systems. There is
  326. also a file called "README" which should be read FIRST - before doing
  327. anything else with the code (this should always be one's first step with
  328. any package).  Further, there is a "changes" file which details what has
  329. changed since the last release - be sure to read this to see what might
  330. need to change in your programs.
  331.  
  332. ========================================================================
  333.  
  334. #1.3. Why does the link step says that some of the functions Tcl needs
  335. are missing when I am trying to build it?
  336.  
  337. Did you run the "configure" program first (via "sh ./configure" or
  338. equivalent)?  Without doing this, things such as strtoul or strerror are
  339. sometimes mentioned as missing.
  340.  
  341. Tcl includes equivalents for at least the following functions and
  342. include files which may not be found on some systems:
  343.  
  344. dirent.h       limits.h          stdlib.h         string.h        opendir.c
  345. strerror.c     strstr.c          strtol.c         strtoul.c        strtod.c
  346.  
  347. ========================================================================
  348.  
  349. #1.4. How do I add BLT to a Tcl(X)/Tk?
  350.  
  351. From ghowlett@fast.net (George A. Howlett) we get the answer:
  352.  
  353. Instead of adding TclX to blt_wish, try it the other way.  Add BLT to
  354. wishx.  It's pretty simple.
  355.  
  356. In the file "./<platform>/tkXAppInit.c", add the a call to the BLT
  357. initialization routine right after line 116.
  358.  
  359.     if (TkX_Init(interp) == TCL_ERROR) {
  360.         return TCL_ERROR;
  361.     }
  362.     if (Blt_Init(interp) != TCL_OK)) {
  363.         return TCL_ERROR;
  364.     }
  365.  
  366. Link wishx with libBLT.a and that's it.
  367.  
  368. *Note:* It is better to use the new dynamic loading capabilities of
  369. Tcl7.5+.  BLT2.1+ and TclX7.5.2+ have the ability to be dynamically
  370. loaded modules.  See their docs on building them as shared libraries and
  371. then see the Tcl man page 'load' for loading it into the system at
  372. runtime.
  373.  
  374. ========================================================================
  375.  
  376. #1.5. How do I create a dynamically loadable library for Tcl/Tk?
  377.  
  378. The team at Sun have provided examples for building a dynamically
  379. loadable library for any supported Tk platform.  You can find this at
  380. ftp://ftp.sunlabs.com/pub/tcl/example.{zip,tar.gz,tar.Z}.
  381.  
  382. ========================================================================
  383.  
  384. #1.6. Where are the '.lib' files for building shared libraries on
  385. Windows?
  386.  
  387. They are distributed separate from the binaries and sources, but in the
  388. same FTP places:
  389.      ftp://ftp.sunlabs.com/pub/tcl/vclibs(version).zip     
  390.     ftp://ftp.neosoft.com/pub/tcl/mirror/ftp.smli.com/vclibs(version).zip
  391.  
  392. ========================================================================
  393.  
  394.  
  395. **
  396. * Running Tk applications
  397. **
  398.  
  399. #2.1. Where can I get info on porting my Tk3 application to Tk4? to
  400. Tk8?
  401.  
  402. Get the Tk3 to Tk4 porting notes from
  403. http://www.sunlabs.com/research/tcl/tk4.0.ps.  This is also covered in
  404. an appendix in the 2nd edition of Welch's Tcl/Tk book.  From Tk4 to Tk8,
  405. there were fewer incompatibilities but more major features introduced.
  406. See http://sunscript.sun.com/TclTkCore/8.0.html for a list of the new
  407. features and some notes on upgrading.
  408.  
  409. ========================================================================
  410.  
  411. #2.2. How do I get my wish application to execute on Unix (I just get
  412. a wish prompt!)?
  413.  
  414. For Unix, most systems require a full pathname to the interpreter.   So
  415. you cannot start a wish script out as
  416.  
  417. #!wish -f
  418.  
  419. Likewise, many Unix systems have a maximum length of characters that you
  420. can put on a #! line.  If you exceed this, you do not get the behavior
  421. you expect.  So do not try to put something like:
  422.  
  423. #!/projects/somethingbig/bin/sun4/wish -f
  424.  
  425. followed by your wish code.  Keep the lines short - under 32 characters
  426. is recommended.  Another option is the following:
  427.  
  428. #!/bin/sh
  429. # This line makes the next one a comment in Tcl \
  430. exec /path/to/wish "$0" ${1+"$@"}
  431.  
  432. the '/path/to/' is unnecessary if you know that wish is in the user's
  433. path.  Be careful to make sure that you are referencing the correct
  434. version of wish.  Tk4+ installs its libraries and executable with the
  435. version number attached by default.
  436.  
  437. ========================================================================
  438.  
  439. #2.3. How do I run Tcl/Tk scripts by double-clicking on Windows/Mac?
  440.  
  441. For Windows95/NT, the installation should associate '.tcl' to launch
  442. wish.  However, if this is not done properly, you can do it yourself by
  443. going to Explorer->View->Options->File Types and creating a file type to
  444. associate to '.tcl' that has the 'open' action as '"C:\Program
  445. Files\Tcl\bin\wish80.exe" "%1"' (or whereever you chose to have wish
  446. installed).
  447.  
  448. You can optionally create an 'Edit' action as well.  Don't choose
  449. 'notepad' as that doesn't understand Unix text files (which just use a
  450. line feed for the end of a line, as opposed to carriage return and line
  451. feed on Windows and just carriage return on the Mac.  I recommend
  452. finding a copy of 'emacs', but 'write' will do.
  453.  
  454. As for the Mac, it's a little more complicated.  Jim Ingham tells us:
  455.  
  456. There are two things here.  One is using scripts in 'TEXT' resources.
  457. The other is double-clickable apps.
  458.  
  459. 1) 'TEXT' resources: Make a named resource of type "TEXT" in the app or
  460. any of its shared libraries, and source it in with the command:
  461.  
  462. source -rsrc resourceName
  463.  
  464. 2) Double-Clickable Apps: define a proc called 'tkOpenDocument'. To get
  465. this to source at startup, you will have to do something like put it in
  466. the Tk 'TEXT' resource of the Tk shared library, or some other script
  467. that gets sourced before or during the Tk startup.  In it you can either
  468. do this to make a droplet:
  469.  
  470. proc tkOpenDocument {args} {
  471.    foreach file $args {
  472.       after idle [list source $file]
  473.    }
  474. }
  475.  
  476. The after idle is necessary if you load any other extensions or scripts
  477. in the startup, since the 'tkOpenDocument' gets run for the Original
  478. Open Document event gets run in the 'Tk_Init' procedure...
  479.  
  480. Or just source in the code for your application, for instance using the
  481. source -rsrc from 1 above.
  482.  
  483. ========================================================================
  484.  
  485. #2.4. How can I get Tk to use 'send' (I get security error messages)?
  486. Does 'send' work on Windows/Mac?
  487.  
  488. Alternate forms of this question often mention that Tk 'send' is broken,
  489. or ask how to use xauth.
  490.  
  491. Since Tk 3.3, the X11 xauth security mechanism is used.  While this
  492. provides more security, it does require the user to do a bit more setup
  493. to use the 'send' command.  The man page for 'send' describes how to
  494. solve this question for the average user.  For those interested in
  495. further reading on auth, look at
  496. ftp://ftp.neosoft.com/pub/tcl/alcatel/docs/Xauthority.gz.
  497.  
  498. You can configure Tk to not depend on xauth by modifying "Makefile.in"
  499. to comment out the following:
  500.  
  501. # To turn off the security checks that disallow incoming sends when
  502. # the X server appears to be insecure, reverse the comments on the
  503. # following lines:
  504. #SECURITY_FLAGS =
  505. SECURITY_FLAGS = -DTK_NO_SECURITY
  506.  
  507. *Note:* It's not a good idea to disable security if security is an issue
  508. for you.  You may want to consult your sysadmin before doing this.
  509.  
  510. 'send' is supported on the Mac or Windows platforms as of Tk8.1.
  511.  
  512. ========================================================================
  513.  
  514. #2.5. How can I ignore send from other applications?
  515.  
  516. Delete the 'send' command.  This removes the interpreter's name from the
  517. X11 property (won't show up in another wish's 'winfo interps') and
  518. disables incoming 'send' processing.  You can delete the send command
  519. with:
  520.  
  521. rename send {}
  522.  
  523. ========================================================================
  524.  
  525. #2.6. Does Tcl/Tk read a resource/startup file?
  526.  
  527. Yes, although the name and location varies by platform.
  528.  
  529.         tclsh            wish
  530. Unix        ~/.tclshrc        ~/.wishrc
  531. Windows        ~/tclsh.rc        ~/wishrc.tcl
  532. Macintosh    (Someone tell me what it is for the Mac)
  533.  
  534. '~' translates into the user's home directory, which usually means 'C:\'
  535. on Windows.
  536.  
  537. ========================================================================
  538.  
  539. #2.7. How can I call Tk scripts from a C program?
  540.  
  541. Several simple examples have been posted to comp.lang.tcl.  Eric Bleeker
  542. <ericbl@paramount.nikhefk.nikhef.nl> was gracious enough to package his
  543. up and place it at
  544. ftp://ftp.neosoft.com/pub/tcl/alcatel/code/tkHelloWorld*. This program
  545. assumes that you have installed the Tcl and Tk libraries, header files,
  546. etc.
  547.  
  548. Alternatively, you can look into creating a dynamically loadable library
  549. of your C code for Tcl/Tk.  Sun has created some basic examples for all
  550. platforms at ftp://ftp.sunlabs.com/pub/tcl/example.{zip,tar.gz,tar.Z}.
  551.  
  552. ========================================================================
  553.  
  554. #2.8. Why does Tk look funny in CDE/VUE?
  555.  
  556. The problem is that this idiotically designed window managers set X
  557. resources for *foreground, *background, *Font, etc..., which gets
  558. imposed on Tk.  The real problem is that CDE apps rely on these
  559. resources being set (no sane defaults).  The following is a quick
  560. wrapper solution.
  561.  
  562. The solution is provided as a shell script which wraps around any Tk
  563. program which you might normally run.  It is assumed that you have
  564. "xrdb" and the program in your regular path.  If this is how you
  565. normally launch your app:
  566.  
  567.     tkcon -slave "lappend auto_path /my/dir" &
  568.  
  569. then you would now do: (notice that the wrapper backgrounds
  570. automatically)
  571.  
  572.     uncde tkcon -slave "lappend auto_path /my/dir"
  573.  
  574. #!/bin/sh
  575. #
  576. # uncde
  577. #
  578. # This script will temporarily remove those lame global resource bindings
  579. # that screw with Tk applications.  It launches the Tk app (which is assumed
  580. # to be in your path), gives it a few seconds to load up, and then restores
  581. # the old resources.
  582. #
  583. # Example usage:    uncde tkcon -slave "set a 50"
  584.  
  585. if test ! "$1"; then
  586.     echo "usage: $0 command options"
  587.     exit
  588. fi
  589.  
  590. ## Cache the old resources
  591. OLD_RESOURCES=`xrdb -query`
  592.  
  593. ## Remove what we didn't want
  594. echo "removing *foreground, *background and *Font resources"
  595. xrdb -remove <<STOP
  596. *foreground:
  597. *Font:
  598. *background:
  599. STOP
  600.  
  601. exec ${1+"$@"} &
  602. echo "\"$1\" backgrounded as process $!"
  603.  
  604. ## Give time for Tk to load up and avoid the old resources
  605. sleep 3
  606.  
  607. ## Add back the old stuff
  608. echo "resetting all resources to defaults"
  609. xrdb -merge <<STOP
  610. $OLD_RESOURCES
  611. STOP
  612.  
  613. ========================================================================
  614.  
  615.  
  616. **
  617. * Tk application bindings (mouse and keyboard)
  618. **
  619.  
  620. #3.1. How can I change the default class bindings?
  621.  
  622. All default class bindings for Tk widgets are initialized in
  623. "$tk_library/tk.tcl".  Use this file as a guide to implement new
  624. bindings.
  625.  
  626. ========================================================================
  627.  
  628. #3.2. How can I delete a binding?
  629.  
  630. Give an empty-string command to the 'bind' invocation.  For example, to
  631. disable the Delete key in all entry fields:
  632.  
  633. bind Entry <Delete> {}
  634.  
  635. Also, see the documentation for the 'bind' and 'bindtags' commands.
  636. There are several ways to disable or modify which types of bindings
  637. (instance, class, etc.) occur and the order in which they are processed.
  638.  
  639. In Tk4.2+, there is an 'event' command which allows for the
  640. specification of virtual event names, like '<<Cut>>'.  Tk4.2+ uses these
  641. for bindings such as Cut/Copy/Paste.  Deleting bindings from a virtual
  642. event works like so:
  643.  
  644. event delete <<Cut>> <Control-x>
  645.  
  646. ========================================================================
  647.  
  648. #3.3. How can I bind to the arrow keys?
  649.  
  650. Arrow keys are bound to <Left>, <Right>, <Up> and <Down>.  Under X11,
  651. keys are referred to by their keysym.  One can use either 'xmodmap -pk'
  652. or the 'xev' program to determine what the keysym a particular key on a
  653. keyboard is currently generating.
  654.  
  655. If the keysym that is being used is not known by Tk, you may have to
  656. edit its "ks_names.h" file.  There is a note in this file that indicates
  657. that one should not edit it - but this is where the keysym must be for
  658. it to be recognized.
  659.  
  660. ========================================================================
  661.  
  662. #3.4. How can I get window manager's mouse bindings to work in my Tk
  663. application?
  664.  
  665. Some window managers, such as mwm, define mouse button bindings which
  666. cause Tk some problems.  Try renaming your window manager's startup file
  667. (something like "~/.twmrc" for instance) and copy in a startup file from
  668. a login id that works.
  669.  
  670. ========================================================================
  671.  
  672. #3.5. How can I add new actions to an existing binding?
  673.  
  674. The binding model in Tk4 allows you to have bindings trigger for a
  675. widget instance without modifying that of the widget's class.  The
  676. following example sets a global variable to the item which a user
  677. selects in a listbox without interfering with Tk's highlighting of that
  678. item:
  679.  
  680. bind .listbox <ButtonRelease-1> { set my_global [%W get [%W nearest %y]] }
  681.  
  682. If you want your binding on the widget instance to be the only event to
  683. trigger (avoiding any possible class or all binding), then add a 'break'
  684. at the end of the binding, like so:
  685.  
  686. bind .listbox <Double-Button-1> { destroy %W; break }
  687.  
  688. If you still want to add to an existing binding, you need to have a '+'
  689. on the first line of the bind command, like so:
  690.  
  691. bind .listbox <Double-Button-1> {+ destroy %W; break }
  692.  
  693. See the documentation for 'bind' and 'bindtags' for more information.
  694.  
  695. ========================================================================
  696.  
  697. #3.6. How do the mouse buttons map when I have less than 3 buttons?
  698.  
  699. For Windows and 2 button mice, '<Button-1>' is the left button and
  700. '<Button-3>' is the right button.  You may have an OS extension which
  701. emulates the 2nd button by pressing both buttons simultaneously.
  702.  
  703. For the Mac, ???
  704.  
  705. For those who lack '<Button-2>', the only core bindings made for that
  706. are fast scanning of listbox, entry and text widgets.  Programmers with
  707. potential users in this category should be sensitive to this loss and
  708. try and offer alternatives (like '<Shift-Button-1>').
  709.  
  710. ========================================================================
  711.  
  712.  
  713. **
  714. * Tk user interface questions
  715. **
  716.  
  717. #4.1. How can I set X11 resources for a wish application in an
  718. app-defaults file?
  719.  
  720. Read the documentation for the 'option' command. Then you should
  721. consider something like the following - assume the program name is
  722. "xwf".
  723.  
  724. The following are two general purpose functions to put into a library:
  725.  
  726. # get_env varName
  727. #   Looks up the environment variable named $varName and returns its value
  728. #   OR {} if it does not exist
  729. proc get_env varName {
  730.     global env
  731.     if {[info exists env($varName)]} { return $env($varName) }
  732. }
  733.  
  734. # loadAppDefaults classNameList ?priority?
  735. #   Searches for the app-default files corresponding to classNames in
  736. #   the order specified by X Toolkit Intrinsics, and loads them with
  737. #   the priority specified (default: startupFile).
  738. proc loadAppDefaults {classNameList {priority startupFile}} {
  739.   set filepath "[split [envVal XUSERFILESEARCHPATH] :]  [envVal XAPPLRESDIR]  [split [envVal XFILESEARCHPATH] :]  /usr/lib/X11"
  740.   foreach i $classNameList {
  741.     foreach j $filepath {
  742.       if {[file exists $j/$i]} {
  743.     option readfile $j/$i $priority; break
  744.       }
  745.     }
  746.   }
  747. }
  748.  
  749. Now, here is what you would put into xwf:
  750.  
  751. option add Tk.BoldFont "*-lucida sans-Bold-R-Normal-*-100-*" widgetDefault
  752. loadAppDefaults {xwf XWF} userDefault
  753.  
  754. This sets a program default, then load any defaults specified in the
  755. user's default resources and finally any site or general app-defaults
  756. resource.   Of course, you would want to add some xwf command line
  757. handling to allow  the user to override things at execution time.
  758.  
  759. Chris Milam contributes the following modification of 'loadAppDefaults'
  760. which follows the X11R5 method of merging app-default files from several
  761. sources.
  762.  
  763. # loadAppDefaults classNameList ?priority?
  764. #   Searches for the app-default files corresponding to classNames in
  765. #   the order specified by X Toolkit Intrinsics (R5), and loads them with
  766. #   the priority specified (default: startupFile).
  767. proc loadAppDefaults {classNameList {priority startupFile}} {
  768.   set lang [envVal LANG]
  769.   if {[string length $lang] > 0} { set lang /$lang }
  770.   set filepath " /usr/lib/X11${lang}/app-defaults  [split [envVal XFILESEARCHPATH] :]  [envVal XAPPLRESDIR]${lang}  [split [envVal XUSERFILESEARCHPATH] :]  "
  771.   foreach i $classNameList {
  772.     foreach j $filepath {
  773.       if {[file exists $j/$i]} {
  774.         option readfile $j/$i $priority;
  775.       }
  776.     }
  777.   }
  778. }
  779.  
  780. ========================================================================
  781.  
  782. #4.2. Can I choose a particular user interface look and feel?
  783.  How do I get native look and feel on Windows/Mac?
  784.  
  785. Tk4 has a Motif compliant look and feel (LAF).  If you want a more
  786. conformant Motif LAF, put:
  787.  
  788. set tk_strictMotif 1
  789.  
  790. as close to the beginning of your program as possible.  Tk reads that
  791. variable dynamically to determine whether it should maintain a strict
  792. Motif LAF.
  793.  
  794. Tk4 strives to be Motif compliant and does not currently use either
  795. XView or Xt based widgets in its user interface, so an OpenLook
  796. compliant (or similar toolkit) interface is not possible.
  797.  
  798. Tk8 has native LAF for Windows and Mac (with Unix maintaining the Motif
  799. LAF).  Tk8 uses the LAF of the system it is on without exception.  You
  800. can get the Tk4 LAF on non-Unix platforms only by modifying the core
  801. files to use the Unix widget counterpart code.
  802.  
  803. ========================================================================
  804.  
  805. #4.3. How can I change the Tk cursor?
  806.  
  807. On Unix, the file "/usr/include/X11/cursorfont.h" for a list of
  808. available cursors.  You can use the names in there by removing the
  809. 'XC_'.  These same cursors are emulated on Windows/Mac. On the Mac you
  810. can also use crsr and CURS style cursors by the name of the resource.
  811. On Unix it possible to define your own cursors.  The 'Tk_GetCursor' man
  812. page describes this in detail, but in short you create an X bitmap file
  813. like so:
  814.  
  815. #define face_width 16
  816. #define face_height 12
  817. #define face_x_hot 7
  818. #define face_y_hot 7
  819. static char face_bits[] = {
  820.   0x00, 0x01, 0x30, 0x06, 0x0c, 0x18, 0x04, 0x10, 0x32, 0x26, 0x32, 0x26,
  821.   0x01, 0x40, 0x81, 0x40, 0x09, 0x48, 0x12, 0x24, 0xe2, 0x23, 0x04, 0x10,
  822.   0x0c, 0x18, 0x30, 0x06, 0xc0, 0x01, 0x00, 0x00};
  823.  
  824. and then configure your cursor with '. configure -cursor [list
  825. @path_to_xbm_file fgColor]'
  826.  
  827. Here's a little proc to make an entire application go busy while it's
  828. doing something. Just call it with the commands you want to execute, and
  829. the watch cursor will be displayed for the time it takes the commands to
  830. complete.  Note that any new windows will have their normal cursor.
  831.  
  832. proc busy {cmds} {
  833.     global errorInfo
  834.  
  835.     set busy {.app .root}
  836.     set list [winfo children .]
  837.     while {$list != ""} {
  838.     set next {}
  839.     foreach w $list {
  840.         set class [winfo class $w]
  841.         set cursor [lindex [$w config -cursor] 4]
  842.         if {[winfo toplevel $w] == $w || $cursor != ""} {
  843.         lappend busy [list $w $cursor]
  844.         }
  845.         set next [concat $next [winfo children $w]]
  846.     }
  847.     set list $next
  848.     }
  849.  
  850.     foreach w $busy {
  851.     catch {[lindex $w 0] config -cursor watch}
  852.     }
  853.  
  854.     update idletasks
  855.  
  856.     set error [catch {uplevel eval [list $cmds]} result]
  857.     set ei $errorInfo
  858.  
  859.     foreach w $busy {
  860.     catch {[lindex $w 0] config -cursor [lindex $w 1]}
  861.     }
  862.  
  863.     if $error {
  864.     error $result $ei
  865.     } else {
  866.     return -code $error $result
  867.     }
  868. }
  869.  
  870. ========================================================================
  871.  
  872. #4.4. How can I change the default colors in Tk?
  873.  
  874. You can change the default colors by modifying your X resource database
  875. for your personal use or use the Tk convenience command 'tk_setPalette'.
  876. You can do the first using whatever method you usually use to
  877. add/modify X resources (X default file, etc.), or you can use the Tk
  878. 'option' command to change the option database from within a Tk
  879. application.  Tk also has the command tk_bisque which reverts Tk4 to
  880. using the Tk3 default colors.  The easiest way to set your application
  881. to one general scheme is via tk_setPalette like so:
  882.  
  883. tk_setPalette pink
  884.  
  885. For more information, see your system's documentation for loading X
  886. resources, and/or the Tk man page for the 'option' and 'tk_setPalette'
  887. commands.
  888.  
  889. ========================================================================
  890.  
  891. #4.5. How do I specify fonts in Tk?
  892.  
  893. For Tk4, fonts are specified in different ways for Unix and Windows/Mac
  894. environments.  For Unix, you want to specify fonts in the X11 font spec
  895. format, like so:
  896.  
  897. .widget config -font "-adobe-courier-bold-r-normal--8-80-75-75-m-50-iso8859-1"
  898.  
  899. Often you will see '*'s replace certain elements of the above font spec.
  900. You can get a full list of fonts on your machine from the command
  901. 'xlsfonts'.  For Windows/Mac environments, the fonts are specified like
  902. so:
  903.  
  904. ## Font spec: {Family Size Style}
  905. .widget config -font {Courier 12 {}}
  906. .widget config -font {Helvetica 18 {Bold Italic}}
  907.  
  908. For valid font spec formats on Win/Mac, Tk will find a font, even if it
  909. is not the specified one.  You should always be careful which fonts you
  910. choose because only a core set can be expected to be on any given
  911. machine.
  912.  
  913. Tk8 has a new 'font' mechanism that allow for the easy specification of
  914. fonts (as above) for all platforms, creating your own named fonts, and
  915. commands to query and manipulate information about available fonts.
  916.  
  917. ========================================================================
  918.  
  919.  
  920. **
  921. * Tk window manager interaction questions
  922. **
  923.  
  924. #5.1. How can I get the geometry of my window (I get 1x1+0+0)?
  925.  
  926. If you start wish interactively and type:
  927.  
  928. puts [wm geometry .]
  929.  
  930. you will get something like:
  931.  
  932. 200x200+90+90
  933.  
  934. The actual numbers may vary depending on X11 defaults, window managers,
  935. etc. If you put the same thing in a script, though:
  936.  
  937. #!/usr/local/bin/wish -f
  938. puts [wm geometry .]
  939.  
  940. You will instead get this:
  941.  
  942. 1x1+0+0
  943.  
  944. This will happen because you are requesting geometry information before
  945. the window has actually been drawn.  In general, before you start asking
  946. about window sizes, use the 'update' command so that the geometries of
  947. the windows can be resolved.  Changing the above script to this will
  948. give the expected results:
  949.  
  950. #!/usr/local/bin/wish -f
  951. update
  952. puts [wm geometry .]
  953.  
  954. ========================================================================
  955.  
  956. #5.2. How can I raise or lower a window?
  957.  
  958. The commands 'raise' and 'lower' are used to change a window's position
  959. in the stacking order, as well as adjust toplevel windows to be
  960. raised/lowered with respect to other windows.
  961.  
  962. ========================================================================
  963.  
  964. #5.3. How can I withdraw/iconify a window?
  965. How can I remap a withdrawn window?
  966.  
  967. 'wm withdraw <toplevel>' will take a window off the screen without
  968. iconifying it.
  969.  
  970. 'wm iconify <toplevel>' will iconify a window (how it looks iconified is
  971. up to the window manager).
  972.  
  973. 'wm deiconify <toplevel>' will remap or deiconify the window.
  974.  
  975. ========================================================================
  976.  
  977. #5.4. How can I use Tk in a subwindow of a non-Tk application?
  978.  
  979. From faustus@CS.Berkeley.EDU (Wayne A. Christopher):
  980.  
  981. Create the Tk toplevel window but don't map it ('wm withdraw
  982. .toplevel').  Then re-parent the window to be a subwindow of your other
  983. one and then map it.  I have done this when the Tk application is a
  984. separate process, but if it's the same process I think you will get into
  985. trouble with the event loop, since each toolkit wants control.
  986.  
  987. *Note:* Tk8 provides better access to this functionality, a spin-off
  988. from making the Tk plugin work.
  989.  
  990. ========================================================================
  991.  
  992. #5.5. How can I mix interactions between Xt and Tk/Tcl?
  993.  
  994. Tk has a new event loop which provides easier interaction than previous
  995. answers dictated.  The following answer is provided by Paolo Brutti
  996. (gi0570@rh0015.roma.tlsoft.it):
  997.  
  998. void XtEventSetup(ClientData xtconn, int flags)
  999. {
  1000.   static Tcl_Time maxDelay={0, 300000}; /* To process non-X events */
  1001.  
  1002.   Tcl_WatchFile((Tcl_File)xtconn, TCL_READABLE);
  1003.   Tcl_SetMaxBlockTime(&maxDelay);
  1004. }
  1005.  
  1006. int XtDoEvent(Tcl_Event *evPtr, int flags)
  1007. {
  1008.   while (XtPending())
  1009.     XtProcessEvent(XtIMAll);
  1010.   return 1;
  1011. }
  1012.  
  1013. void XtEventCheck(ClientData xtconn, int flags)
  1014. {
  1015.   Tcl_Event *event;
  1016.  
  1017.   if(XtPending()) {
  1018.     event    = (Tcl_Event *)ckalloc(sizeof(Tcl_Event));
  1019.     event->proc    = XtDoEvent;
  1020.     Tcl_QueueEvent(event, TCL_QUEUE_TAIL);
  1021.   }
  1022. }
  1023.  
  1024. void tkGo (void)
  1025. {
  1026.   extern Widget topLevel;
  1027.   Tcl_File xtconn;
  1028.   int xtfd = ConnectionNumber(XtDisplay(topLevel));
  1029.  
  1030.   xtconn = Tcl_GetFile((ClientData)xtfd, TCL_UNIX_FD);
  1031.  
  1032.   Tcl_CreateEventSource(XtEventSetup, XtEventCheck, (ClientData)xtconn);
  1033.   while (1) {
  1034.     Tcl_DoOneEvent(TCL_ALL_EVENTS);
  1035.   }
  1036. }
  1037.  
  1038. ========================================================================
  1039.  
  1040. #5.6. How can I bind the ResizeRequest event?
  1041.  
  1042. The 'ResizeRequest' event is used (typically by window managers) to
  1043. interpose on configuration changes before they occur, possibly
  1044. preventing them from occurring altogether and support for it was removed
  1045. in Tk4.  There is almost no imaginable case where Tk scripts should
  1046. really be asking for 'ResizeRequest' events; people tended to use them
  1047. when what they really wanted was 'Configure' events (which trigger after
  1048. the resize has occured), and this produced very strange behavior in
  1049. their programs.
  1050.  
  1051. Try 'bind .widget <Configure> { puts "%W is now %w x %h" }' instead.
  1052.  
  1053. ========================================================================
  1054.  
  1055. #5.7. What is the difference between wm and winfo?
  1056.  
  1057. 'wm' (short for window_manager) is used for managing or finding
  1058. information about 'toplevels', while 'winfo' (short for widget_info) is
  1059. for querying info about all types of widgets.
  1060.  
  1061. For example, 'wm geometry .' will give you the size of the main
  1062. toplevel, including window manager decoration, as perceived by the
  1063. window manager.  However, 'winfo geometry .' returns only the size of
  1064. "." as perceived by Tk.
  1065.  
  1066. ========================================================================
  1067.  
  1068. #5.8. How can I prevent my toplevel from being destroyed?
  1069. How do I make my toplevel ignore the window manager delete button?
  1070.  
  1071. You can capture the window manager delete window action with the
  1072. following:
  1073.  
  1074. wm protocol .toplevel WM_DELETE_WINDOW { puts "Don't delete me" }
  1075.  
  1076. This overrides the window manager's default action, so if you wanted to
  1077. have a clean up procedure execute before closing the window, you have to
  1078. make sure to close the window yourself.
  1079.  
  1080. ========================================================================
  1081.  
  1082. #5.9. How can I prevent my toplevel from being iconified?
  1083.  
  1084. You can trap the unmapping of the window and immediately redisplay it
  1085. with the following:
  1086.  
  1087. bind .toplevel <Unmap> { wm deiconify %W }
  1088.  
  1089. ========================================================================
  1090.  
  1091. #5.10. How can I keep my toplevel on top?
  1092.  
  1093. There are two methods for keeping your toplevel on top.  Make your
  1094. choice depending on your needs:
  1095.  
  1096. The first method is for modal dialogs, where you want to ensure that the
  1097. dialog does not get obscured by its associated toplevel window.  It is
  1098. assumed that you already have done a local 'grab' on the dialog to make
  1099. it modal.  All you have to do then is call 'wm transient .dialog
  1100. .master' to ensure that the dialog will remain on top.  This is somewhat
  1101. window manager dependent, but works in general.
  1102.  
  1103. The second method is more forceful, for when you want a window to not be
  1104. obscured at all.  To create this effect, do the following:
  1105.  
  1106. bind .toplevel <Visibility> {
  1107.     if {[string match %W .toplevel] &&
  1108.     [string compare %s VisibilityUnobscured]} {
  1109.     raise %W
  1110.     update
  1111.     }
  1112. }
  1113.  
  1114. It's been reported that Windows doesn't report '<Visibility>', but it
  1115. does handle transient well.  However, if you really want something
  1116. forceful, then the following is it.  It is a proc which just calls raise
  1117. on your toplevel and reschedules itself:
  1118.  
  1119. proc keep_raised toplevel {
  1120.     if {[winfo exists $toplevel]} {
  1121.     raise $toplevel
  1122.     after 1000 [info level 0]
  1123.     }
  1124. }
  1125.  
  1126. ========================================================================
  1127.  
  1128. #5.11. Is Tk fully ICCCM compliant?
  1129.  
  1130. In short, no.  However, it is possible to make Tk more ICCCM compliant
  1131. through the use of a few 'wm' methods.  The following are a couple
  1132. examples which effect window manager interaction:
  1133.  
  1134. wm command . "$argv0 $argv"
  1135. wm client . [info hostname]
  1136.  
  1137. ========================================================================
  1138.  
  1139.  
  1140. **
  1141. * Tk 'canvas' widgets questions
  1142. **
  1143.  
  1144. #6.1. How can I get output from a Tk canvas?
  1145.  
  1146. The Tk 'canvas' has a 'postscript' method which allows one to create an
  1147. Encapsulated Postscript file describing the canvas. Unfortunately this
  1148. does not currently work for images in the canvas.
  1149.  
  1150. To get better postscript support, as well as a generally enhanced
  1151. canvas, get the Tk dash patch
  1152. (http://www.worldaccess.nl/~nijtmans/dash.html) by Jan Nijtmans
  1153. (mailto:nijtmans@worldaccess.nl).
  1154.  
  1155. ========================================================================
  1156.  
  1157. #6.2. How can I fill a canvas area which is bounded by lines as
  1158. opposed to a shape like a polygon, oval, etc.?
  1159.  
  1160. You must use a polygon if you want to fill an area bounded by some
  1161. lines.
  1162.  
  1163. ========================================================================
  1164.  
  1165. #6.3. How can I raise/lower canvas window objects or draw graphics
  1166. onto a window object inside a canvas?
  1167.  
  1168. Use 'raise .widget' and 'lower .widget' to adjust window objects
  1169. relative to each other.  However, graphics objects cannot be raised
  1170. above window objects on the 'canvas'.  See the 'canvas' man page for the
  1171. full set of options.
  1172.  
  1173. ========================================================================
  1174.  
  1175. #6.4. How can I detect when the canvas has been resized?
  1176.  
  1177. You need to bind a command to the Configure event, like this:
  1178.  
  1179. bind .canvas <Configure> { puts "%W is now %w %h" }
  1180.  
  1181. ========================================================================
  1182.  
  1183. #6.5. How can I use a list of coordinates in a variable to create a
  1184. polygon (or any other item)?
  1185.  
  1186. This is actually a pure Tcl question, but it comes up frequently in this
  1187. context, so here we go...
  1188.  
  1189. All canvas items require two or more coordinates on creation, which
  1190. define the initial position and/or shape of the item.  If you have each
  1191. coordinate in a separate variable, or you are using a constant value,
  1192. then creating canvas items is simple.  For example:
  1193.  
  1194.     .myCanvas create rectangle $x1 $y1 $x2 $y2 -fill blue
  1195.     .myCanvas create text 100 250 -text "Hello, world"
  1196.  
  1197. Many times, though, the coordinates don't each exist in a separate
  1198. variable.  They may be a list in a single variable that was read from a
  1199. file, or returned from some calculation routine, or extracted from some
  1200. other list of coordinates.  In this case, you need to break the list of
  1201. coordinates up before the canvas command is executed.  Use the 'eval'
  1202. commands for this.  Here are several examples:
  1203.  
  1204. # Example 1
  1205. # Given a list of two coordinates, create a text item
  1206. #
  1207. set coords {150 50}
  1208. eval .myCanvas create text $coords -text hello
  1209.  
  1210. # Example 2
  1211. # Here's a routine that returns coordinates for a rectangle centered
  1212. # around a point, and some example uses.
  1213. #
  1214. proc CenteredRectangle {x y width height} {
  1215.     return [list [expr {$x - $width/2.0}]  [expr {$y - $height/2.0}]  [expr {$x + $width/2.0}]  [expr {$y + $height/2.0}]]
  1216. }
  1217. eval .myCanvas create rectangle [CenteredRectangle 80 5 10 75]
  1218. eval .myCanvas create rectangle [CenteredRectangle 5 80 75 10]
  1219. eval .myCanvas create oval [CenteredRectangle 140 110 75 50]
  1220.  
  1221. # Example 3
  1222. # Here's a routine which creates a text label surrounded by
  1223. # a rectangle, with both of them centered around a given point.
  1224. #
  1225. proc CenteredBoxLabel {w x y text} {
  1226.     set id [$w create text $x $y -text $text -anchor center]
  1227.     eval $w create rectangle [$w bbox $id]
  1228. }
  1229. CenteredBoxLabel .myCanvas 33 42 "Hello, world"
  1230.  
  1231. If you have a list of coordinate pairs, e.g. {{25 10} {30 12} {35 14}},
  1232. then an extra step is required to make it a flat list.  Try this:
  1233.  
  1234. # Example 4
  1235. # Starting with a list of pairs...
  1236. #
  1237. set coordPairs {{25 10} {30 12} {35 14}}
  1238.  
  1239. # ... flatten out the list into just a list of numbers (as in
  1240. # the above examples).
  1241. #
  1242. set flatList [eval concat $coordPairs]
  1243.  
  1244. # Now, follow the same strategy as in the examples above.
  1245. #
  1246. eval .myCanvas create line $flatList
  1247.  
  1248. In summary, carefully read the docs for 'eval', 'concat', and 'list' so
  1249. that you can combine the coordinate data with the 'canvas create'
  1250. command to form a valid Tcl command which can be executed.
  1251.  
  1252. ========================================================================
  1253.  
  1254. #6.6. How can I speed up 'canvas' performance?
  1255.  
  1256. Often times coding style changes can result in increased performance,
  1257. but the 'canvas' has its limits.  The Tk dash patch
  1258. (http://www.worldaccess.nl/~nijtmans/dash.html) by Jan Nijtmans
  1259. (mailto:nijtmans@worldaccess.nl) has many canvas improvements, including
  1260. one or two that can improve performance in some situations.
  1261.  
  1262. ========================================================================
  1263.  
  1264. #6.7. How can I put/print an image on the 'canvas'?
  1265.  
  1266. To put an image into the 'canvas' you must first create it with 'image
  1267. create ...' and then embed that image into the canvas.  For example:
  1268.  
  1269. image create photo my_image -file [file join $tk_library demos images teapot.ppm]
  1270. pack [canvas .c]
  1271. .c create image 0 0 -anchor nw -image my_image
  1272.  
  1273. Unfortunately Tk does not yet support the printing of images.  You can
  1274. get this functionality by grabbing the Tk dash patch
  1275. (http://www.worldaccess.nl/~nijtmans/dash.html) by Jan Nijtmans
  1276. (mailto:nijtmans@worldaccess.nl).
  1277.  
  1278. ========================================================================
  1279.  
  1280. #6.8. Why doesn't the 'canvas' seem to start at 0,0?
  1281.  
  1282. The canvas coords are skewed by the highlight border and the relief.  By
  1283. default, they overlap onto the canvas coord space.  There are two ways
  1284. to deal with this:
  1285.  
  1286. ## Method 1, zero out the highlightthickness and borderwidth
  1287. ## (borderwidth defaults to zero) anyway
  1288. .canvas config -borderwidth 0 -highlightthickness 0
  1289.  
  1290. ## Method 2, adjust the canvas position to expose 0,0 properly
  1291. .canvas xview moveto 0
  1292. .canvas yview moveto 0
  1293.  
  1294. Method 2 is better, but you must do it anytime you adjust the canvas
  1295. borderwidth or highlightthickness.
  1296.  
  1297. ========================================================================
  1298.  
  1299. #6.9. Does the 'canvas' have a 'see' method?
  1300.  
  1301. The 'canvas' lacks a 'see' method like that available in the 'text' or
  1302. 'listbox' widgets.  The following code provides the equivalent
  1303. functionality for a canvas:
  1304.  
  1305. ## "see" method alternative for canvas
  1306. ## Aligns the named item as best it can in the middle of the screen
  1307. ## Behavior depends on whether -scrollregion is set
  1308. ##
  1309. ## c    - a canvas widget
  1310. ## item - a canvas tagOrId
  1311. proc canvas_see {c item} {
  1312.     set box [$c bbox $item]
  1313.     if [string match {} $box] return
  1314.     if [string match {} [$c cget -scrollreg]] {
  1315.     ## People really should set -scrollregion you know...
  1316.     foreach {x y x1 y1} $box {
  1317.         set x [expr round(2.5*($x1+$x)/[winfo width $c])]
  1318.         set y [expr round(2.5*($y1+$y)/[winfo height $c])]
  1319.     }
  1320.     $c xview moveto 0
  1321.     $c yview moveto 0
  1322.     $c xview scroll $x units
  1323.     $c yview scroll $y units
  1324.     } else {
  1325.     ## If -scrollregion is set properly, use this
  1326.     foreach {x y x1 y1} $box {top btm} [$c yview]  {left right} [$c xview] {p q xmax ymax} [$c cget -scrollreg] {
  1327.         set xpos [expr (($x1+$x)/2.0)/$xmax - ($right-$left)/2.0]
  1328.         set ypos [expr (($y1+$y)/2.0)/$ymax - ($btm-$top)/2.0]
  1329.     }
  1330.     $c xview moveto $xpos
  1331.     $c yview moveto $ypos
  1332.     }
  1333. }
  1334.  
  1335. ========================================================================
  1336.  
  1337.  
  1338. **
  1339. * Tk 'entry' widgets questions
  1340. **
  1341.  
  1342. #7.1. How can I initialize an entry widget with some text?
  1343.  
  1344. You can use the '-textvariable' option for an 'entry' widget as follows:
  1345.  
  1346. set default "foobar"
  1347. entry .foo -width 25 -textvariable default
  1348.  
  1349. or you can specifically insert text into the entry (only works when the
  1350. entry widget is configured as '-state normal'):
  1351.  
  1352. entry .foo
  1353. .foo insert 0 "foobar"
  1354.  
  1355. ========================================================================
  1356.  
  1357. #7.2. How can I limit entry widget input (length or type of chars)?
  1358.  
  1359. You want to make use of combination of the 'entry' widget's
  1360. '-textvariable' option and the tcl variable 'trace' function.  Here is a
  1361. limited example:
  1362.  
  1363. proc forceInt {name el op} {
  1364.     global $name ${name}_int
  1365.     if [string comp {} $el] {
  1366.     set old  ${name}_int\($el)
  1367.     set name $name\($el)
  1368.     } else { set old ${name}_int }
  1369.     if ![regexp {^[-+]?[0-9]*$} [set $name]] {
  1370.     set $name [set $old]
  1371.     bell; return
  1372.     }
  1373.     set $old [set $name]
  1374. }
  1375.  
  1376. pack [label .la -text {Integer 2: {^[-+]?[0-9]*$}}] -anchor w
  1377. pack [entry .a -textvariable myVar] -fill x -expand 1
  1378. trace variable myVar w forceInt
  1379. set myVar {}
  1380.  
  1381. You can see a more complex example as a Tk plugin
  1382. (http://sunscript.sun.com/products/plugin.html) at
  1383. http://www.cs.uoregon.edu/research/tcl/code/tclet/entrylimit.html.
  1384.  
  1385. ========================================================================
  1386.  
  1387.  
  1388. **
  1389. * Tk 'listbox' widgets questions
  1390. **
  1391.  
  1392. #8.1. How can I select multiple items that are not adjacent in the
  1393. listbox at one time?
  1394.  
  1395. Use the '-selectmode' option of the 'listbox' to specify what type of
  1396. selection you desire.  The modes 'multiple' and 'extended' will allow
  1397. you to select multiple non-contiguous entries. See the 'listbox' man
  1398. page for more information.
  1399.  
  1400. ========================================================================
  1401.  
  1402. #8.2. How can I select items in more than one Tk listbox at a time?
  1403.  
  1404. The default for Tk's 'listbox' widget is to export its selection as the
  1405. X selection.  There can only be one of these at a time.  To turn off
  1406. this behavior in Tk, use '-exportselection false' when you create the
  1407. 'listbox'.  Alternatively, place the following command at the beginning
  1408. of your script:
  1409.  
  1410. option add *Listbox.exportselection false
  1411.  
  1412. ========================================================================
  1413.  
  1414. #8.3. How can I avoid fractional white space at the end of a resizable
  1415. listbox?
  1416.  
  1417. Use '-setgrid 1' when you create the 'listbox'.  Note that only one
  1418. widget can properly have setgrid set per toplevel.  See the 'options'
  1419. man page for more information.  It works like so:
  1420.  
  1421. listbox .l -setgrid 1 -yscrollcommand ".s set" -relief sunken -bd 2
  1422. scrollbar .s -command ".l yview"
  1423. pack .s -side right -fill y
  1424. pack .l -side top -fill both -expand 1
  1425. .l insert end one two three four five six seven eight nine ten LAST
  1426.  
  1427. *Note:* You may have only one widget per toplevel use '-setgrid'.
  1428.  
  1429. ========================================================================
  1430.  
  1431. #8.4. How can I scroll multiple listboxes with one scrollbar?
  1432.  
  1433. Scrollbars have a '-command' option which is used to tell scrollable
  1434. widgets (e.g. 'listbox', 'text', 'entry') how to position themselves
  1435. when the scrollbar is moved.  This command typically looks like:
  1436.  
  1437. scrollbar .scroll -command {.scrollable_widget yview}
  1438.  
  1439. where 'xview' can substitute for 'yview'.  Before the command is
  1440. executed, however, it will have two numbers concatenated to it.  The
  1441. numbers are fractional positions which indicate how the scrollable
  1442. widget should position itself.  Thus, to have a single scrollbar control
  1443. multiple widgets, simply use a procedure as the scroll command, and have
  1444. that procedure scroll as many widgets as you would like.  The procedure
  1445. should take a two arguments (i.e. the fractional positions).  The
  1446. following example will connect multiple listboxes to one scrollbar and
  1447. correctly handle button bindings in each for single/browse selection:
  1448.  
  1449. set BOXES {.lb0 .lb1 .lb2 .lb3}
  1450.  
  1451. proc LBset args {
  1452.     global BOXES
  1453.     foreach lb $BOXES { eval $lb $args }
  1454. }
  1455.  
  1456. proc LBscroll args {
  1457.     eval .sy set $args
  1458.     LBset yview moveto [lindex $args 0]
  1459. }
  1460.  
  1461. scrollbar .sy -orient v -command [list LBset yview]
  1462. pack .sy -fill y -side right
  1463.  
  1464. foreach lb $BOXES {
  1465.     listbox $lb -exportsel no -selectmode browse -yscrollcommand LBscroll
  1466.     pack $lb -side left -fill both -expand 1
  1467.  
  1468.     bind $lb <ButtonPress-1> {
  1469.     LBset select clear 0 end
  1470.     LBset select set [%W nearest %y]
  1471.     }
  1472.     bind $lb <B1-Motion> {
  1473.     LBset select clear 0 end
  1474.     LBset select set [%W nearest %y]
  1475.     LBset see [%W nearest %y]
  1476.     }
  1477.     bind $lb <ButtonRelease-1> {
  1478.     LBset select clear 0 end
  1479.     LBset select set [%W nearest %y]
  1480.     }
  1481. }
  1482.  
  1483. for {set i 100} {$i} {incr i -1} {LBset insert end $i}
  1484.  
  1485. To get proper behavior with the keys as well, you will have to shadow
  1486. the bindings for key movement found in "$tk_library/listbox.tcl".
  1487.  
  1488. ========================================================================
  1489.  
  1490. #8.5. Why doesn't '.listbox curselection' or 'selection get' return
  1491. the proper item when I make a button binding to my listbox?
  1492.  
  1493. The best way to get the selected item during a button click event on a
  1494. 'listbox' is to use the following code:
  1495.  
  1496. bind .listbox <Button-1> { set item [%W get [%W nearest %y]] }
  1497.  
  1498. This ensures that the item under the pointer is what will be returned as
  1499. 'item'.  The reason '.listbox curselection' can fail is because the
  1500. items in 'curselection' are not set until the 'Listbox' class binding
  1501. triggers, which is after the instance bindings by defaults.  This is the
  1502. same reason for which 'selection get' can fail, but it will also fail if
  1503. you set the '-exportselection' option to 0.
  1504.  
  1505. ========================================================================
  1506.  
  1507. #8.6. Can I have different colored lines in a listbox?
  1508.  
  1509. This is not possible with the standard Tk4 'listbox'.  Some attempts
  1510. have been made to make megawidget listboxes with this functionality
  1511. based on the 'text' or 'canvas' widget. The Tix
  1512. (http://www.xpi.com/tix/) megawidget extension provides an extended
  1513. listbox.
  1514.  
  1515. ========================================================================
  1516.  
  1517.  
  1518. **
  1519. * Tk 'menu' widget questions
  1520. **
  1521.  
  1522. #9.1. How can I get the tearoff menu to reflect changes in the regular
  1523. menu?
  1524.  
  1525. At the moment torn-off menus will not reflect changes made to the
  1526. original menu.  This functionality is slated for an upcoming revision of
  1527. the 'menu' system in Tk.  It's possible to do this now by tracking the
  1528. associated tearoff using the '-tearoffcommand' option for menus.  This
  1529. allows you to specify a command that will be executed when the menu is
  1530. torn off.  The widget names of the menu and tearoff menu (tearoffs are
  1531. created as toplevels with the name '.toplevel.tearoff<id>' when torn
  1532. off) are appended to this command before it is evaluated.
  1533.  
  1534. ========================================================================
  1535.  
  1536. #9.2. Why do I have problems accessing item/index 0 of my menu?
  1537.  
  1538. Tearoffs are new to Tk4 and the new default for 'menu's.  They now
  1539. occupy index 0 of the menu when they are present.  You can exclude them
  1540. by passing '-tearoff 0' to each menu or by placing the following line at
  1541. the beginning of your code:
  1542.  
  1543. option add *Menu.tearoff 0
  1544.  
  1545. ========================================================================
  1546.  
  1547. #9.3. How do know when I am over a specific entry in a menu?
  1548.  
  1549. Tk menu entries are not first class widgets, thus they do not generate
  1550. their own '<Entry>' and '<Leave>' events.  However, Tk8 provides the
  1551. virtual event '<<MenuSelect>>' that simulates this.  An example of its
  1552. use can be found in the '$tk_library/demos/menu.tcl' file for Tk8.  In
  1553. Tk4, this can be simulated with a binding to '<Any-Motion>'.
  1554.  
  1555. ========================================================================
  1556.  
  1557.  
  1558. **
  1559. * Tk 'text' widgets questions
  1560. **
  1561.  
  1562. #10.1. How can I pack a text widget so that it can be resized
  1563. interactively?
  1564.  
  1565. When using the 'pack' geometry manager, use '-expand 1', as in the
  1566. following:
  1567.  
  1568. pack [text .text] -fill both -expand 1
  1569.  
  1570. When using the 'grid' geometry manager, do the following:
  1571.  
  1572. grid [text .text] -sticky news
  1573. grid rowconfigure 0 -weight 1
  1574. grid columnconfig 0 -weight 1
  1575.  
  1576. ========================================================================
  1577.  
  1578. #10.2. Why do I get an extra newline from the text widget?
  1579.  
  1580. For internal reasons, the 'text' widget maintains a newline at the end
  1581. of the text widget.  In order to avoid having this added to what was
  1582. actually input into the text widget, use '.text get 1.0 end-1c' to get
  1583. the full text out of a text widget.
  1584.  
  1585. ========================================================================
  1586.  
  1587. #10.3. How can I check to see if the text widget contents have
  1588. changed?
  1589.  
  1590. The 'text' widget does not have a '-textvariable' option like the
  1591. 'entry' widget, so you must be more devious in determining when the
  1592. contents have changed.
  1593.  
  1594. If the contents of the text widget are known to be small, then a simple
  1595. solution would be to cache the original contents and use 'string compare
  1596. $cache [.text get 1.0 end-1c]' to check for changes.
  1597.  
  1598. A more general solution that some have recommended is to make bindings
  1599. that set a global flag when the text widget is edited.  This is often
  1600. imperfect because you have to make sure to account for all bindings
  1601. which might edit the widget.  Also, you don't really want these bindings
  1602. to trigger all the time, but rather just once after any save command.
  1603. Alternatively, you could place a wrapper proc around the text widget
  1604. which intercepts any insert/delete calls:
  1605.  
  1606. pack [text .text]
  1607. set .text 1; # Represents whether text is SAVED or not
  1608. rename .text ..text
  1609. proc .text args {
  1610.     global .text
  1611.     if [regexp {^(ins|del).*} [lindex $args 0]] { set .text 0 }
  1612.     uplevel ..text $args
  1613. }
  1614.  
  1615. The only thing that misses is direct C calls and embedded window
  1616. addition.  Don't forget to 'set .text 1' when you save text.
  1617.  
  1618. ========================================================================
  1619.  
  1620. #10.4. How can I maintain read-only sections of a text widget?
  1621.  
  1622. If you want the entire text widget to be read-only, set the "-state"
  1623. option of the 'text' widget to "disabled".  To create read-only sections
  1624. in a text widget, you should make use of the 'text' widget tag facility.
  1625.  The following is a minimal example of this:
  1626.  
  1627. pack [text .text]
  1628. .text tag config readonly -background yellow
  1629. rename .text ..text
  1630. proc .text args {
  1631.     if {[string match ins* $args] &&
  1632.     [lsearch -exact [.text tag names [lindex $args 1]] readonly]>-1} return
  1633.     if [string match del* $args] {
  1634.     if [string comp {} [lindex $args 2]] {
  1635.         if {[string comp {} [eval .text tag nextrange  readonly [lrange $args 1 2]]]} return
  1636.     } else {
  1637.         if {[lsearch -exact [.text tag names  [lindex $args 1]] readonly]>-1} return
  1638.     }
  1639.     }
  1640.     uplevel ..text $args
  1641. }
  1642.  
  1643. ========================================================================
  1644.  
  1645. #10.5. Is there an overwrite/overstrike mode for text/entry widget?
  1646.  
  1647. Not by default, but you can change the tkTextInsert and tkEntryInsert
  1648. library procedures to include this with the following:
  1649.  
  1650. proc tkTextInsert {w s} {
  1651.     global tkPriv
  1652.     if {($s == "") || ([$w cget -state] == "disabled")} {
  1653.         return
  1654.     }
  1655.     if {[catch {
  1656.         if {[$w compare sel.first <= insert]
  1657.                 && [$w compare sel.last >= insert]} {
  1658.             $w delete sel.first sel.last
  1659.         }
  1660.     }] && [info exists tkPriv(overwrite)] && $tkPriv(overwrite)} {
  1661.         if {[$w compare "insert+[string len $s]c" < "insert lineend"]} {
  1662.             $w delete insert "insert+[string length $s]c"
  1663.         } else {
  1664.             $w delete insert "insert lineend"
  1665.         }
  1666.     }
  1667.     $w insert insert $s
  1668.     $w see insert
  1669. }
  1670.  
  1671. proc tkEntryInsert {w s} {
  1672.     global tkPriv
  1673.     if {$s == ""} {
  1674.         return
  1675.     }
  1676.     if {[catch {
  1677.         set insert [$w index insert]
  1678.         if {([$w index sel.first] <= $insert)
  1679.                 && ([$w index sel.last] >= $insert)} {
  1680.             $w delete sel.first sel.last
  1681.         }
  1682.     }] && [info exists tkPriv(overwrite)] && $tkPriv(overwrite)} {
  1683.         $w delete insert [expr [$w index insert]+[string length $s]]
  1684.     }
  1685.     $w insert insert $s
  1686.     tkEntrySeeInsert $w
  1687. }
  1688.  
  1689. Thus you just set the tkPriv(overwrite) variable to 0/1 to switch
  1690. between the overwrite and insert modes.
  1691.  
  1692. ========================================================================
  1693.  
  1694. #10.6. How can I always see the end of the text widget?
  1695.  
  1696. The problem is you add text to the text widget but you can't see it
  1697. because it is now off the screen.  Instead of requiring any interaction
  1698. from the user, you can use either of the following lines of code:
  1699.  
  1700. .text see end ;# works anytime for text widgets
  1701. # OR
  1702. .text yview moveto 1 ;# works for other widgets with scrollbars attached
  1703.  
  1704. ========================================================================
  1705.  
  1706. #10.7. Does the text widget have undo?
  1707.  
  1708. The text widget does not have a built-in core undo functionality, but it
  1709. is possible to create such in Tcl.  The method is similar to maintaining
  1710. read-only sections of a text widget, whereby the programmer must catch
  1711. every instance of insert and delete and store them.
  1712.  
  1713. Depending on whether you want unlimited undo, you also want redo, or you
  1714. want to capture tags as well, the exact functionality changes.  Examples
  1715. of working undo functionality have been posted on news:comp.lang.tcl and
  1716. can be found via http://www.dejanews.com/.
  1717.  
  1718. ========================================================================
  1719.  
  1720.  
  1721. **
  1722. * Miscellaneous Tk widget questions
  1723. **
  1724.  
  1725. #11.1. How can I create a scrollable window of buttons?
  1726.  
  1727. The easy way to do this is to make the buttons the children of a
  1728. 'canvas' widget, place them in the canvas with 'canvas create window
  1729. ...' and attach a 'scrollbar' to the canvas.  For example:
  1730.  
  1731. scrollbar .sy -orient v -command ".c yview"
  1732. canvas .c -yscrollcommand ".sy set"
  1733. pack .sy -fill y -side right
  1734. pack .c -fill both -expand 1 -side left
  1735. set x 2
  1736. set y 2
  1737. for {set i 0} {$i<20} {incr i} {
  1738.     button .c.b$i -text "Button $i" -width 10 -command "puts {$i pressed}"
  1739.     .c create window $x $y -window .c.b$i -anchor nw
  1740.     incr y [winfo reqheight .c.b$i]
  1741. }
  1742. .c config -scrollregion "0 0 [winfo reqwidth .c.b0] $y"  -width [winfo reqwidth .c.b0]
  1743.  
  1744. ========================================================================
  1745.  
  1746. #11.2. How can I create a widget with an upper case name?
  1747.  
  1748. You can't.  During a recent revision of Tk, things were changed so that
  1749. names beginning with a capital letter are reserved for class names.
  1750. Specific instances of widgets must begin with a lower case letter.  This
  1751. enables X11 resource definitions to distinguish between a class and an
  1752. instance.
  1753.  
  1754. ========================================================================
  1755.  
  1756. #11.3. How can I vertically align radio/check buttons regardless of
  1757. font?
  1758.  
  1759. Note the following example:
  1760.  
  1761. radiobutton .times -text Times -anchor w -value Times
  1762. radiobutton .helvetica -text Helvetica -anchor w -value Helvetica
  1763. radiobutton .courier -text Courier -anchor w -value Courier
  1764. pack .times .helvetica .courier -side top -fill x
  1765.  
  1766. Note that you are using anchor west in the widgets themselves, and not
  1767. in the packer.  This lets the packer produce full width buttons.
  1768.  
  1769. ========================================================================
  1770.  
  1771. #11.4. How can I group a set of radiobuttons together?
  1772.  
  1773. To group radiobuttons, simply give all the buttons in a group the same
  1774. '-variable' name.  Since the default variable name is 'selectedButton'
  1775. for *all* radiobuttons, if no '-variable' is used, then *all* belong to
  1776. the same group.
  1777.  
  1778. radiobutton .left.b1 -text "Left 1"  -variable leftChoice -value left1
  1779. radiobutton .left.b2 -text "Left 2"  -variable leftChoice -value left2
  1780. radiobutton .left.b3 -text "Left 3"  -variable leftChoice -value left3
  1781.  
  1782. radiobutton .right.b1 -text "Right 1" -variable rightChoice -value right1
  1783. radiobutton .right.b2 -text "Right 2" -variable rightChoice -value right2
  1784. radiobutton .right.b3 -text "Right 3" -variable rightChoice -value right3
  1785.  
  1786. ========================================================================
  1787.  
  1788.  
  1789. **
  1790. * Tk image questions
  1791. **
  1792.  
  1793. #12.1. Does Tk support JPEG/GIF/XPM/etc?
  1794.  
  1795. As of Tk4.2, Tk supports XBM (X bitmap) for bitmaps as well as PPM
  1796. (portable pixmap, a 24 bit format) and GIF (graphics interchange format)
  1797. for 'photo images'.  Currently only PPM and XBM support the '-data'
  1798. option.
  1799.  
  1800. The Tk Image Extension
  1801. (ftp://ftp.nici.kun.nl/pub/nici/software/tcltk/img/) by Jan Nijtmans
  1802. (mailto:nijtmans@worldaccess.nl) contains format handlers for XBM, XPM,
  1803. JPEG, GIF89, PNG and TIFF and the 'pixmap' image type adopted from Tix
  1804. (http://www.xpi.com/tix/).  Further image formats can be added via DLLs
  1805. with the Tk C command 'Tk_CreateImageType' (along with code to read that
  1806. format, of course).
  1807.  
  1808. ========================================================================
  1809.  
  1810. #12.2. How can I specify bitmap/image patterns on the command line
  1811. instead of as a file name?
  1812. What is the format of the '-data' option for images?
  1813.  
  1814. For XBM and PPM formatted images, the 'image' command in Tk allows you
  1815. to pass a '-data' option that would contain the image data in the same
  1816. format as you'd have in a file.
  1817.  
  1818. *Note:* The Tk plugin (http://sunscript.sun.com/products/plugin.html)
  1819. and Tk8.0+ can read base64 encoded GIF data via '-data', but this isn't
  1820. available in Tk4.2- unless you get the excellent Tk plus patch
  1821. (http://www.worldaccess.nl/~nijtmans/plus.html) by Jan Nijtmans
  1822. (mailto:nijtmans@worldaccess.nl).
  1823.  
  1824. ========================================================================
  1825.  
  1826. #12.3. How do I get Tk to recognize the transparency in my GIF images?
  1827.  
  1828. Tk uses a hack for transparency in GIF images.  If you have a GIF89
  1829. image that has the transparency index set, you need to set the global
  1830. Tcl variable 'TRANSPARENT_GIF_COLOR' to the color which you want the
  1831. show through (in general, the background of the widget you are placing
  1832. it on).  Use the following code as an example:
  1833.  
  1834.  
  1835.     label .x
  1836.     set TRANSPARENT_GIF_COLOR [.x cget -bg]
  1837.     image create photo x -file image.gif
  1838.     .x config -image x
  1839.  
  1840. Donal Fellows has a minimal C extension to support real transparency at
  1841. http://r8h.cs.man.ac.uk:8000/tcl/transPhoto.c
  1842.  
  1843. Tk8 removes the need for this hack, properly implementing transparency
  1844. in GIF images (some bugs may still exist).
  1845.  
  1846. ========================================================================
  1847.  
  1848. #12.4. How can I get bitmaps created with 'image' to work with
  1849. '-stipple'?
  1850.  
  1851. At the moment, you can't.  Bitmaps created with 'image create bitmap
  1852. ...' do not use 'Tk_DefineBitmap', which is required for '-stipple' to
  1853. know it's a bitmap.  Instead, you'll have to use the old format for
  1854. using bitmaps in stipples, like so:
  1855.  
  1856. .canvas create rect 10 10 80 80 -fill black -stipple @/path/to/my.bmp
  1857.  
  1858. It's not a simple C fix for the above problem, but it's on Sun's ToDo
  1859. list.
  1860.  
  1861. ========================================================================
  1862.  
  1863.  
  1864. **
  1865. * Tk geometry manager questions
  1866. **
  1867.  
  1868. #13.1. How can I find my invisible windows when using the packer?
  1869.  
  1870. The situation: A window is created, say '.w1', followed by another
  1871. window, say '.w2'.  The command 'pack .w1 -in .w2' is used to pack '.w1'
  1872. inside of '.w2'.  The 'pack' command completes successfully, and 'pack
  1873. info .w1' indicates that things are as expected.  However, '.w1' isn't
  1874. visible!  Where is it?
  1875.  
  1876.     button .w1 -text Hello;    # create .w1
  1877.     frame .w2;        # create .w2
  1878.     pack .w1 -in .w2;    # pack .w1 inside .w2 
  1879.     pack .w2;        # pack .w1 in main window
  1880.                 # where's the button?
  1881.  
  1882. The explanation: (based on a posting by js@aelfric.bu.edu (Jay Sekora))
  1883.  
  1884. The short answer is 'raise .w1'.  In the example '.w1' is positioned
  1885. properly inside '.w2', and all the sizing glue that lets '.w1' and '.w2'
  1886. adjust their sizes based on each other will work, but '.w1' is
  1887. underneath '.w2', because windows are stacked in the order they are
  1888. created in, by default.  You can change the stacking order explicitly
  1889. with the 'raise' command, in this case 'raise .w1'.
  1890.  
  1891. ========================================================================
  1892.  
  1893. #13.2. How can I get 'cget' to return the correct size of a resized
  1894. widget?
  1895. ('.widget cget -width|height' returns the wrong size!)
  1896.  
  1897. Don't use a widget's 'cget' method, use ''winfo' width|height .widget'
  1898. instead.  The 'cget' method will only tell you what the widget wanted to
  1899. be or what you told it to be with '.widget config -width|height ...'.
  1900. If the packer resizes it to fill the slave space, or the user resizes
  1901. it, then only 'winfo' will return the actual new size.
  1902.  
  1903. ========================================================================
  1904.  
  1905. #13.3. How can I add a row/col to the grid?
  1906.  
  1907. There is a simple Tcl solution for this, provided by Stephen Uhler,
  1908. (with modification by Donal Fellows):
  1909.  
  1910. # insert rows or columns into a grid
  1911. #  grid:  the geometry master
  1912. #  what:  row or column
  1913. #  index: where to insert
  1914. #  count: how many rows/cols to insert
  1915.  
  1916. proc grid_insert {grid what index {count 1}} {
  1917.     foreach slave [grid slaves $grid] {
  1918.     array set info [grid info $slave]
  1919.     if {$info(-$what) >= $index} {
  1920.         incr info(-$what) $count
  1921.         eval {grid $slave} [array get info]
  1922.     } elseif {$info(-$what)+$info(-${what}span) > $index} {
  1923.         incr info(-${what}span) $count
  1924.         eval {grid $slave} [array get info]
  1925.     }
  1926.     }
  1927. }
  1928.  
  1929. ========================================================================
  1930.  
  1931.  
  1932. **
  1933. * Miscellaneous Tk questions
  1934. **
  1935.  
  1936. #14.1. How can I get the name of my own interpreter?
  1937.  
  1938. 'tk appname' or 'winfo name .' returns the name of your Tk interpreter
  1939. as seen by others.
  1940.  
  1941. ========================================================================
  1942.  
  1943. #14.2. How can I destroy every window except '.'?
  1944.  
  1945. The answer is:
  1946.  
  1947. eval destroy [winfo children .]
  1948.  
  1949. The 'eval' is necessary so that the list of children windows can be
  1950. separated into individual arguments.  Destroy will get individual window
  1951. names instead of one big string.
  1952.  
  1953. ========================================================================
  1954.  
  1955. #14.3. How can I get drag & drop functionality in my program?
  1956.  
  1957. The BLT (http://www.tcltk.com/blt/) extension has this functionality.
  1958.  
  1959. You can also try the all-tcl code by Donal Fellows at
  1960. http://r8h.cs.man.ac.uk:8000/tcl/.
  1961.  
  1962. ========================================================================
  1963.  
  1964. #14.4. How can I get a double-click to ignore a single-click?
  1965.  
  1966. In short, you can't.  A single-click will always register at least once
  1967. - in the interval between the clicks of a double-click.  Tk does not
  1968. delay evaluation of a mouse button binding to see if the user will
  1969. double or triple click.  You can prevent a second single-click binding
  1970. from triggering by adding a 'break' to the end of the double-click
  1971. binding.
  1972.  
  1973. ========================================================================
  1974.  
  1975. #14.5. How can I warp the mouse pointer?
  1976.  
  1977. This functionality is not provided by Tk (it's considered improper to
  1978. warp the user's cursor in general).  However, you can make a simple
  1979. dynamically loadable library to do it.  Here is the core code:
  1980.  
  1981. int
  1982. Tk_CursorCmd(clientData, interp, argc, argv)
  1983. ClientData clientData;
  1984. Tcl_Interp *interp;                 /* Current interpreter. */
  1985. int argc;                           /* Number of arguments. */
  1986. char **argv;                        /* Argument strings. */
  1987. {
  1988.   int length;
  1989.   char c;
  1990.   Tk_Window tkwin = (Tk_Window) clientData;
  1991.   Tk_Window winPtr;
  1992.  
  1993.   if (argc < 2) {
  1994.     Tcl_AppendResult(interp, "wrong # args:  should be \"",
  1995.                      argv[0], " ?options?\"", (char *) NULL);
  1996.     return TCL_ERROR;
  1997.   }
  1998.  
  1999.   length = strlen(argv[1]);
  2000.   c = argv[1][0];
  2001.   if ( c == 'w' && strncmp(argv[1],"warp",length) == 0 ) {
  2002.     int x,y;
  2003.     Window win;
  2004.  
  2005.     if (argc != 5) {
  2006.       Tcl_AppendResult(interp, "wrong # args:  should be \"",
  2007.                        argv[0], " warp <window> <x> <y>\"", (char *) NULL);
  2008.       return TCL_ERROR;
  2009.     }
  2010.     if ( argv[2][0] == '.' ) {
  2011.       winPtr = (Tk_Window ) Tk_NameToWindow(interp, argv[2], tkwin);
  2012.       if (winPtr == NULL) {
  2013.         return TCL_ERROR;
  2014.       }
  2015.       win = Tk_WindowId(winPtr);
  2016.     } else {
  2017.       winPtr = (Tk_Window )clientData;
  2018.       win = None;
  2019.     }
  2020.  
  2021.     if  ( Tk_GetPixels(interp,winPtr,argv[3],&x) != TCL_OK )return TCL_ERROR;
  2022.     if  ( Tk_GetPixels(interp,winPtr,argv[4],&y) != TCL_OK )return TCL_ERROR;
  2023.  
  2024.     XWarpPointer(Tk_Display(winPtr),None,win,0,0,0,0,x,y);
  2025.   }
  2026.  
  2027.   return TCL_OK;
  2028. }
  2029.  
  2030. You'll of course need an 'Foo_Init' function with something like:
  2031.  
  2032. Tcl_CreateCommand(interp, "cursor", Tk_CursorCmd,
  2033.         (ClientData) Tk_MainWindow(interp), NULL);
  2034.  
  2035. That will give you a command that understands 'cursor warp <window> <X>
  2036. <Y>'.  The Tk dash patch (http://www.worldaccess.nl/~nijtmans/dash.html)
  2037. also has added this functionality to the Tk 'event' command by adding a
  2038. '-warp' option, which is more robust than the above.
  2039.  
  2040. ========================================================================
  2041.  
  2042. #14.6. How do I run wish programs without a display?
  2043. How do I run my wish program on a server?
  2044.  
  2045. At the moment this is not possible in Tk without modifying the code.
  2046. This feature is on Sun's ToDo list.
  2047.  
  2048. ========================================================================
  2049.  
  2050. #14.7. Is there a difference between stand-alone Tk and the Tk plugin?
  2051.  
  2052. Yes.  While regular Tk and the Tk plugin
  2053. (http://sunscript.sun.com/products/plugin.html) are based off the same
  2054. source code, the plugin is subtly different due to its web-based
  2055. interaction.  Primarily, the security policies for the plugin remove
  2056. certain commands from being evaluated in the interpreter (the plugin
  2057. code is run in a safe interpreter).  Also, there are some enhancements
  2058. to the plugin (as of v2 of the plugin) such as the ability to
  2059. intercommunicate with other applets or other sites when being run.  See
  2060. the Tk Plugin FAQ (http://sunscript.sun.com/techcorner/faq.html) for
  2061. more information.
  2062.  
  2063. The plugin works with Netscape 3.0+ or Microsoft Explorer 3.0+ for Unix,
  2064. Mac or Windows.
  2065.  
  2066. ========================================================================
  2067.  
  2068. #14.8. How can I do terminal emulation in Tk?
  2069.  
  2070. Courtesy of Don Libes (mailto:libes@nist.gov):
  2071.    +  Tk has no built-in terminal widget.  There have been a few attempts at
  2072. making a terminal widget as a Tk extension but none of these implementations
  2073. have been maintained (i.e., are available for the current version of Tk).
  2074. This isn't surprising since all of them had significant limitations and it's
  2075. not clear that this was a sensible approach in the first place.
  2076.    +  Borrow an external terminal emulator.  In particular, you can use
  2077. TkSteal to control an xterm.  You can also control an xterm with
  2078. Expect (http://expect.nist.gov/).  With TkSteal, your xterm physically appears inside the Tk
  2079. application.  And you can send X events to the emulator just like the user.
  2080. In contrast, Expect gives you control of the backend of the emulator -
  2081. so you can make the terminal display what you want, rather than being
  2082. restricted to the output of some existing program.  Similarly, when the user
  2083. enters keystrokes, you can read them and decide if you want to handle them
  2084. or pass them on to another program.  If you want control of both the user
  2085. interface and the backend, you can use both TkSteal and Expect together.
  2086.    +  Emulate a terminal using a text widget.  You can do dumb terminal
  2087. emulation by using Expect's 'expect_before' command to match characters
  2088. and insert them into the widget.  Expect's tkterm example performs smart
  2089. terminal emulation.  It's capable of handling emacs, vi, or any
  2090. termcap/terminfo/curses-based program.  And since it's done with a text
  2091. widget, you can manipulate the display simply by accessing the text widget.
  2092. Exploring_Expect http://www.ora.com/www/item/expect.html covers
  2093. both dumb and smart terminal emulation in the Tk chapter.
  2094.  
  2095. ========================================================================
  2096.  
  2097.  
  2098. **
  2099. * Questions on Tk related extensions/applications
  2100. **
  2101.  
  2102. #15.1. What is incrTcl/incrTk?
  2103.  
  2104. [incr Tcl] (http://www.tcltk.com/itcl/) provides the extra language
  2105. support needed to build large Tcl/Tk applications.  It introduces the
  2106. notion of objects, which act as building blocks for an application.
  2107. Each object is a bag of data with a set of procedures or 'methods' that
  2108. are used to manipulate it.  Objects are organized into 'classes' with
  2109. identical characteristics, and classes can inherit functionality from
  2110. one another.  This object-oriented paradigm adds another level of
  2111. organization on top of the basic variable/procedure elements, and the
  2112. resulting code is easier to understand and maintain.
  2113.  
  2114. [incr Tk] (http://www.tcltk.com/itk/) is a framework for building
  2115. megawidgets using the [incr Tcl] (http://www.tcltk.com/itcl/) object
  2116. system. Megawidgets are high-level widgets like a file browser or a tab
  2117. notebook that act like ordinary Tk widgets but are constructed using Tk
  2118. widgets as component parts, without having to write C code. In effect, a
  2119. megawidget looks and acts exactly like a Tk widget, but is considerably
  2120. easier to implement.
  2121.  
  2122. ========================================================================
  2123.  
  2124. #15.2. What is BLT?
  2125.  
  2126. BLT (http://www.tcltk.com/blt/) is an extension to the Tk toolkit,
  2127. adding new widgets (like a 2D graph widget), another geometry manager
  2128. (now subsumed by Tk's 'grid'), and others commands. It does not require
  2129. any patching of the Tcl or Tk source files.
  2130.  
  2131. A patch to get BLT (http://www.tcltk.com/blt/) running on Windows or the
  2132. latest Tk is available at http://www.jessikat.demon.co.uk/.
  2133.  
  2134. ========================================================================
  2135.  
  2136. #15.3. What is Tix?
  2137.  
  2138. Tix (http://www.xpi.com/tix/) (Tk Interface Extension) is an extensive
  2139. set of over 40 megawidgets including ComboBox, Motif style
  2140. FileSelectBox, MS Windows style FileSelectBox, PanedWindow, NoteBook,
  2141. Hierarchical List, Directory Tree and File Manager, among others.
  2142.  
  2143. ========================================================================
  2144.  
  2145. #15.4. Is there a GUI builder available?
  2146.  What is SpecTcl/XF/Visual Tcl?
  2147.  
  2148. There are a few GUI (Graphical User interface) builders available for
  2149. Tk.
  2150.  
  2151. The most recent entrant is SpecTcl
  2152. (http://sunscript.sun.com/products/spectcl.html), in development by the
  2153. guys at Sun (see the Tcl Home Page (http://sunscript.sun.com/)), which
  2154. can output Perl, Tcl or Java UI code and is 'grid' based.
  2155.  
  2156. XF is the oldest major GUI builder app for Tcl/Tk and is available at
  2157. http://www.cimetrix.com/sven/xf.html.
  2158.  
  2159. Visual Tcl (not the SCO version of Tcl) is a new GUI builder with some
  2160. IDE features for Tcl/Tk and is available at
  2161. http://www.neuron.com/stewart/vtcl/.
  2162.  
  2163. ========================================================================
  2164.  
  2165. #15.5. Is there a spreadsheet/table widget in Tk?
  2166.  What is TkTable?
  2167.  
  2168. TkTable is a Tk widget extension intended to fill the gap of a table or
  2169. spreadsheet widget for Tk.  It is not a full-fledged spreadsheet, but
  2170. has all the basic capabilities for making one.  It can be found at
  2171. http://www.cs.uoregon.edu/research/tcl/capp/.
  2172.  
  2173. ========================================================================
  2174.  
  2175. #15.6. What other languages besides Tcl does Tk work with?
  2176.  What is this (Perl|Scheme|Guile|.*)/Tk I've heard about?
  2177.  
  2178. Tk, as a user interface toolkit, has been grafted onto many other
  2179. languages.  There is an effort underway to develop a Tcl independent Tk
  2180. for any language to easily adapt Tk as its UI extension.  Among the many
  2181. languages which currently make use of Tk:
  2182.    +  Tcl Ada Shell (http://www.ocsystems.com/xada/tash/)
  2183.    +  Guile/Tk docs (http://nis-www.lanl.gov/~rosalia/mydocs/guile-programmer_2.html)
  2184.    +  Oz and Tk (http://www.isg.sfu.ca/oz/#tk)
  2185.    +  Perl/Tk FAQ (http://w4.lns.cornell.edu/~pvhp/ptk/ptkTOC.html)
  2186.    +  Prolog and Tk (http://www.athena.auth.gr/doc/eclipse/html/protcl.html)
  2187.    +  Python and Tk (http://www.python.org/doc/life-preserver/)
  2188.    +  Scheme/Tk FAQ (http://ltiwww.epfl.ch/~furrer/STk/FAQ.html)
  2189.  
  2190. ========================================================================
  2191.  
  2192.  
  2193. **
  2194. * Reporting bugs, Asking further questions, Other resources
  2195. **
  2196.  
  2197. #16.1. My question isn't answered here.  What do I do now?
  2198. What is the netiquette for posting to the newsgroup?
  2199.  
  2200. Thanks for looking here first.  There are two newsgroups for the Tcl
  2201. language: news:comp.lang.tcl for basic discussion of bugs, problems and
  2202. ideas, and news:comp.lang.tcl.announce for announcements of new versions
  2203. of Tcl/Tk and related applications.  Aside from the basic netiquette of
  2204. posting to newsgroups, the following conventions should be followed:
  2205.    +  Don't make the subject just "Help", start questions with "[Q]":
  2206. and write a one-liner (<70 chars) that makes sense.
  2207.    +  Include the version of Tcl/Tk you are using
  2208.    +  Include the OS you are using
  2209.    +  If you compiled it yourself, include the name and version of the compiler
  2210.    +  Be as detailed, but brief, as possible with your question.  Don't just
  2211. send across a 100 line script and ask what's wrong.  Try and narrow down the
  2212. problem as much as possible.
  2213.    +  Include error messages AND the lines that caused them.  Sometimes it is
  2214. not necessary to include the entire error message.  Try and parse it down as
  2215. much as possible without losing relevant information.
  2216.    +  Lurk.  Lurkers are good on Q&A groups such as news:comp.lang.tcl because very
  2217. few questions are original.
  2218.    +  Make sure to include your email address so respondants can CC: you in
  2219. email.  This is the best way to prevent lost messages and question reposts.
  2220. The reverse is true for respondents - don't forget to CC: the person as well
  2221. as make a follow-up to the newsgroup.
  2222.  
  2223. 'Pnews' on UNIX is the general tool for posting to newsgroups. Netscape
  2224. 3+ also has facilities to post to a newsgroup if you have the news
  2225. server preferences set up correctly.
  2226.  
  2227. You can also search previous postings to the newsgroup by using the
  2228. search engine at http://www.dejanews.com/.  Select the power search,
  2229. create a query filter and specify comp.lang.tcl, then do a find on the
  2230. topic of interest.
  2231.  
  2232. ========================================================================
  2233.  
  2234. #16.2. I think I found a bug in Tk.  How do I go about reporting it?
  2235.  
  2236. In the unlikely event you encounter a bug in Tk, make sure to go through
  2237. the following process before posting to news:comp.lang.tcl.
  2238.    1  Have you isolated the bug to make sure that Tk (or Tk's interaction with
  2239. something) is directly at fault?
  2240.    2  Are you using the most recent version of Tk?  If not, make sure that
  2241. the bug has not already been fixed by the newest version.
  2242.    3  Certain it's a bug?  Don't send directly to mailto:bugs@scriptics.com unless
  2243. you are 99.9% certain.  Instead, post to news:comp.lang.tcl.  There are many experts
  2244. lurking there who might be able to answer your question without the need
  2245. to interrupt Dr. John & co. while they are busy fixing all those bugs.
  2246.    4  Start the subject line with "BUG:" and make the subject relevant to
  2247. the bug within a 70 character limit.
  2248.    5  If you have a patch, use "PATCH:" and also send to mailto:patches@scriptics.com.
  2249.    6  Include a brief script (10-20 lines) that reproduces the problem if
  2250. possible.  Make sure it doesn't rely on extensions or site-specific info.
  2251.    7  Explain how to reproduce the bug (press_button_X_...) if
  2252. necessary, and what you were expecting to occur.
  2253.    8  If you believe it is an extension at fault, see the FAQ for that
  2254. extension or post to the newsgroup and make sure to include your full
  2255. Tcl/Tk + extensions setup.
  2256.  
  2257. ========================================================================
  2258.  
  2259. #16.3. There's a bug in the FAQ.  How do I go about reporting it?
  2260.  
  2261. I'm sure that the problem is really the fault of corruption during
  2262. transmission of the FAQ.  However, concerned netizens should report any
  2263. problems with this FAQ to the maintainer: Jeffrey Hobbs
  2264. (mailto:jeff.hobbs@acm.org).
  2265.  
  2266. ========================================================================
  2267.  
  2268. #16.4. What documentation can I find online?
  2269.  
  2270. There is a lot of raw information available for download about Tk on the
  2271. net.  Here are some references of note:
  2272.    +  Tcl Home Page (http://sunscript.sun.com/)
  2273.    +  Tcl/Tk man pages (http://sunscript.sun.com/man/) in HTML
  2274.    +  Tk quick reference guide (ftp://ftp.slac.stanford.edu/software/TkMail/tkref-4.1.0.tar.gz)
  2275.    +  Tcl WWW archive (http://www.neosoft.com/tcl/)
  2276.    +  Tcl Introductory FAQ (http://www.teraform.com/~lvirden/tcl-faq/part1.html)
  2277.    +  Tcl Language Usage FAQ (http://www.psg.com/~joem/tcl/faq.html)
  2278.    +  Tk Windows Usage FAQ (http://www.pconline.com/~erc/tclwin.htm)
  2279.  
  2280. ========================================================================
  2281.  
  2282.  
  2283. Last generated: Tue Apr 28 11:28:26 MEZ 1998 by Jeffrey Hobbs
  2284. (http://www.cs.uoregon.edu/~jhobbs/)
  2285.  
  2286. -- 
  2287.     Jeffrey Hobbs        "I'm really just a Tcl-bot"
  2288.     jeff.hobbs at acm.org | Jeffrey.Hobbs at oen.siemens.de
  2289.