home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 1994-03-23 | 58.2 KB | 1,735 lines
Newsgroups: comp.lang.tcl,comp.answers,news.answers Path: bloom-beacon.mit.edu!hookup!news.kei.com!eff!neoucom.edu!news.ysu.edu!malgudi.oar.net!chemabs!lvirden From: lwv26@cas.org (Larry W. Virden) Subject: FAQ: comp.lang.tcl Frequently Asked Questions (2/5) (Last updated: March 22, 1994) Message-ID: <tcl.p2_764373488@cas.org> Followup-To: comp.lang.tcl Summary: A regular posting of the comp.lang.tcl Frequently Asked Questions (FAQ) and their answers. This is the second of five parts. This part covers the how-to questions and answers. Originator: lwv26@srv01s4 Keywords: tcl, expect, extended tcl, wish, tk Sender: lvirden@cas.org Supersedes: <tcl.p2_761953031@cas.org> Reply-To: lvirden@cas.org (Larry W. Virden) Organization: Chemical Abstracts Service References: <tcl.p1_764373488@cas.org> Date: Tue, 22 Mar 1994 21:58:23 GMT Approved: news-answers-request@MIT.Edu Expires: Tue, 3 May 1994 21:58:08 GMT Lines: 1711 Xref: bloom-beacon.mit.edu comp.lang.tcl:10855 comp.answers:4291 news.answers:16760 Archive-name: tcl-faq/part2 Version: 4.7 Last-modified: March 22, 1994 Please do not be offended if I neglect to acknowledge your contribution to this FAQ! I sometimes forget to put an attribution in. I especially try to add them if it appears that there is further experimentation or debugging being done though. For more information concerning Tcl (see "tcl-faq/part1"), (see "tcl-faq/part3"), (see "tcl-faq/part4"), or (see "tcl-faq/part5"). Index of questions: VIII. Questions on building Tcl and friends on your system: Q8A. Is there anywhere I can find help with the details of getting Tcl to work on my machine? Q8B. Why does the link step says that some of the functions Tcl, needs are missing when I am trying to build it? Q8C. Has anyone built Tcl 6 on an RS/6000 AIX 3.1? Q8D. Has anyone gotten Tcl to compile under HP-UX? Q8E. Has anyone gotten Tcl to compile under VMS? Q8F. What does it take to get Tcl to compile under SCO Unix? Q8G. Why do I get format and scan errors when I run tclTest (NeXT, AIX, etc.)? Q8H. Why do I get lots of errors under Irix 4.0.1 when I run tclTest? Q8I. Does anyone else have problems with Tcl on a Cray? Q8J. Does anyone know how to get Tk to run on a SparcBook or other laptop with a limited number of colors? Q8K. What does it take to get Tcl/Tk to compile on 386bsd/Linux or other POSIX/ANSI C systems not already supported? Q8L. Why do I get a parse error in tkInit.c when I try to compile Tk on my Irix machine? Q8M. What do I need to do to install Tcl 7.x/Tk 3.x on NeXTSTEP 3.1? Q8N. Why can't I print the draft of the Tcl/Tk book? Q8O. Why am I getting errors on my SGI Indigo workstation? Q8P. How do I build expect on Solaris 2.3? IX. How, in Tcl, can I XXX: Q9A. get association lists or property lists? Q9B. call one proc with the multi parameter value returned by another proc? Q9C. pass an array into a proc? Q9D. pipe output of a command back into a Tcl parsing procedure? Q9E. merge extended Tcl into other programs such as wish or expect? Q9F. delete a procedure from within a script? Q9G. get parray to recognize an array variable I have created via upvar? Q9H. get more than 7 digits of double precision? Q9I. grab the command line whenever a non-built-in call is made? Q9J. get or set an environment variable? Q9K. use numbers with leading zeroes? Q9L. find the command line arguments to my application? Q9M. put comments in my script, for example in a case statement? Q9N. redirect stdin or stdout safely, including binary data? Q9O. trap signals, and other more Unix specific functions? Q9P. get quoted strings to work the way I want? Q9Q. share procedures between multiple tcl applications? Q9R. get items inserted into a list? Q9S. perform a non-blocking read on a file identifier? Q9T. read and write from a pipe without locking up? X. How, in Tk, can I XXX: A. Question on starting Tk applications Q10.A.1. get my wish application to execute - I just get a wish prompt! Q10.A.2. ,using a machine with less than 8 bit color, run? Q10.A.3. set X11 resources for a wish application in an app-defaults file? Q10.A.4. specify bitmap patterns on the command line instead of as a file name? Q10.A.5. get a Motif user interface? Q10.A.6. get an OpenLook user interface? Q10.A.7. get Tk 3.3 to even start - I get security error messages. B. Questions on Tk applications and the keyboard Q10.B.1. change the default class bindings? Q10.B.2. delete a binding? Q10.B.3. change a binding while it is being executed? Q10.B.4. bind the arrow key on my Sun keyboard? Q10.B.5. get root's mouse bindings to work in my Tk application? C. Questions on Tk and X11 interactions Q10.C.1. get an application to also use libXt? Q10.C.2. change the X11 cursor? Q10.C.3. raise or lower a window? Q10.C.4. re-map a withdrawn window id? Q10.C.5. use Tk in a subwindow of a non-Tk X11 application? Q10.C.6. bind <Enter> and <Leave> to a frame containing other widgets? Q10.C.7. mix interactions between Xt and Tk/Tcl? D. Questions on Tk listboxes Q10.D.1. resize a listbox? Q10.D.2. select two items that are not adjacent in the listbox at one time? Q10.D.3. select items in more than one Tk listbox at a time? Q10.D.4. avoid fractional white space at the end of a resizable listbox? E. Questions on Tk canvases Q10.E.1. get output from a Tk canvas? Q10.E.2. fill a canvas which is bounded by lines as opposed to a shape like a polygon, oval, etc.? Q10.E.3. raise/lower canvas window objects or draw graphics onto a window object inside a canvas? Q10.E.4. detect when the canvas has been resized? F. Other questions Q10.F.1. get the name of my own interpreter? Q10.F.2. get -relief to work on my text widgets? Q10.F.3. create a scrollable window of buttons? Q10.F.4. pack a text widget so that it can be resized interactively? Q10.F.5. create a widget with an upper case name? Q10.F.6. create equal sized buttons? Q10.F.7. vertically stack radio buttons aligning regardless of font? Q10.F.8. initialize an entry widget with some text? End of FAQ Index ---------------------------------------------------------------------- ------------------------------ From: -VIII- Questions on building Tcl and friends on your system Subject: -Q8A- Is there anywhere I can find help with the details of getting Tcl to work on my machine? A8A. Glad you asked! Look in the Tcl distribution for the file called "porting.notes". This will contain a collection of notes that various people have provided about porting Tcl to various machines and operating systems. There are also a file called "README" which should be read FIRST - before doing anything else with the code (this should always be one's first step with any package). Finally, there is a "changes" file which details what has changed since the last release - be sure to read this to see what might need to change in your programs. ------------------------------ From: -VIII- Questions on building Tcl and friends on your system Subject: -Q8B- Why does the link step says that some of the functions Tcl, needs are missing when I am trying to build it? A8B. Did you run the "config" program first, by doing a "csh ./config" or equivalent? Without doing this, things such as strtoul or strerror are sometimes mentioned as missing. Tcl includes equivalents for at least the following functions and include files which may not be found on some systems: dirent.h limits.h stdlib.h string.h opendir.c strerror.c strstr.c strtol.c strtoul.c strtod.c ------------------------------ From: -VIII- Questions on building Tcl and friends on your system Subject: -Q8C- Has anyone built Tcl 6 on an RS/6000 AIX 3.1? A8C. See porting notes - especially the note about strtoul. One user got Tcl to compile with a few minor source modifications (for example, duplicate case statements for errno and signal symbols in tclUnixStr.c). A few other problems arose in the tests. One is caused by AIX printf not formatting %#x and %#o correctly when the value to be printed is zero: they print "0x0" and "00" instead of "0" and "0" respectively. This was reported as not a problem in earlier releases. No fixes have been posted. Finally, a problem occurs in open.test. test 13.6 hangs because "cat" on the RS6000 is unbuffered. A workaround is to change the execution of "cat" in open.test to do a "cat -u". Dov Grobgeld <dov@menora.weizmann.ac.il> provided info on creating Tcl and Tk shared libraries under AIX 3.1.5: For Tcl: cc -o tkshar.o *.o -bE:tclshar.exp -bM:SRE -berok -lX11 -lm ar r libtclshr tclshar.o For Tk: cc -o tkshar.o *.o -bE:tkshar.exp -bM:SRE -berok -Ltcl -lX11 -lm -ltclshr ar r libtkshr tkshar.o where tckshar.exp and tkshar.exp had lists of the external functions. There are also problems with fonts on AIX and the IBM. A patch is needed from IBM to fix the X server so that fonts are working ------------------------------ From: -VIII- Questions on building Tcl and friends on your system Subject: -Q8D- Has anyone gotten Tcl to compile under HP-UX? A8D. See the porting notes. ------------------------------ From: -VIII- Questions on building Tcl and friends on your system Subject: -Q8E- Has anyone gotten Tcl to compile under VMS? A8E. Information from jkimball@src.honeywell.com (John Kimball) on May 4, 1993 was that he had gotten Tcl 6.7 and Tk 3.2 ported to VMS 5.5. See the catalog for the file information. ------------------------------ From: -VIII- Questions on building Tcl and friends on your system Subject: -Q8F- What does it take to get Tcl to compile under SCO Unix? A8F. Add a "#undef select" to tkEvent.c, and remove the reference to TK_EXCEPTION around line 460 of main.c. Tk uses its own scheme for allocating the border colors for its 3D widgets, which causes problems when running TK on a system with "PseudoColor" display class, and a 16-cell colormap. If you can't go to eight bitplanes, you can instead start the server with a "-static" (Xsco) or "-analog" (Xsight) option, making the display class become "StaticColor". This makes the entire colormap read-only, and it will return the color that most closely maps to the desired color as possible. This information is from Keith Amann <Keith_Amann@stortek.com> ------------------------------ From: -VIII- Questions on building Tcl and friends on your system Subject: -Q8G- Why do I get format and scan errors when I run tclTest (NeXT, AIX, etc.)? A8G. That's a problem (scanf/printf) many systems seem to have. Don't worry too much about it - just don't use these 'advanced' features. If you're hacking C, you'll have the same problems. ------------------------------ From: -VIII- Questions on building Tcl and friends on your system Subject: -Q8H- Why do I get lots of errors under Irix 4.0.1 when I run tclTest? A8H. There's a bug in the 4.0.1 optimizer that's fixed in 4.0.2. Compile tclVar.c using -O0 (no optimization). ------------------------------ From: -VIII- Questions on building Tcl and friends on your system Subject: -Q8I- Does anyone else have problems with Tcl on a Cray? A8I. See the porting notes for a set of changes mentioned. Also, Booker C. Bense <benseb@grumpy.sdsc.edu> reports that version 3.0.1.6 has some real problems with char pointers, causing Tcl to crash. Using version 3.0.2.1, things are much better, except for a minor formatting problem and serious problems with scan. ------------------------------ From: -VIII- Questions on building Tcl and friends on your system Subject: -Q8J- Does anyone know how to get Tk to run on a SparcBook or other laptop with a limited number of colors? A8J. On a SparcBook, if you start openwin (the OpenWindows server starting command) as: openwin -dev "/dev/fb staticvis" you get a static visual color model that Tk copes with better than the default. Some things are ugly, but not as ugly as monochrome. ------------------------------ From: -VIII- Questions on building Tcl and friends on your system Subject: -Q8K- What does it take to get Tcl/Tk to compile on 386bsd/Linux or other Posix/ANSI C systems not already supported? A8K. Patches for 386BSD were posted to comp.lang.tcl back in Nov. 1992 to alt.sources. See one of the ftp archive sites for this group for them. Basically, there were some setting of defines and a few places where const char * had to be used in place of char *. ------------------------------ From: -VIII- Questions on building Tcl and friends on your system Subject: -Q8L- Why do I get a parse error in tkInit.c when I try to compile Tk on my Irix machine? A8L. Jon Knight <J.P.Knight@loughborough.ac.uk> reports that the version of Irix that he is using doesn't define a uid_t. One needs to define one somewhere (or comment out the lines causing the problems) to get the compile to continue. ------------------------------ From: -VIII- Questions on building Tcl and friends on your system Subject: -Q8M- What do I need to do to install Tcl 7.1/Tk 3.4 on NeXTSTEP 3.1? A8M. I have indicated in the past that this particular question seems to generate controversy - I have replaced previous explanations with the latest msg from someone who sounds authoritative... From: Robert Nicholson <robert@steffi.demon.co.uk> This is for TCL7.1 and TK3.4 This is a variation on Thomas Funke's entry. Installing TCL7.1 on NeXT ========================= To install tcl7.1 on NeXTSTEP 3.1 you must: - run configure with predefined CPP: type "sh" to run a Bourne shell. then type CPP='cc -E' ./configure - edit Makefile: add tmpnam.o to COMPAT_OBJS: COMPAT_OBJS = getcwd.o waitpid.o strtod.o tmpnam.o At this point you probably want to rename the all calls to strtod and tmpnam to something else in order to distinguish them from those that are supplied in the NeXT libraries libsys_a.a. You can do this by adding the following line to AC_FLAGS -Dstrtod=newstrtod -Dtmpnam=newtmpnam and renaming the names of the definitions in the appropriate compat/*.c files. To check everything is working correctly open a tclsh % expr {"0" == "+"} 0 Using the wrong strtod function will cause this test to return 1 which is a serious error. Ignore the precision errors. Installing TK3.4 on NEXTSTEP 3.1 ================================ There is a call to strtod in TK3.4 so you should link against ../tcl-7.1/compat/strtod.o and apply the -Dstrtod=newstrtod to AC_FLAGS in Tk also. Note:Tk's raise test will fail when running the tvtwm window manager. Changing to either twm or even better fvwm ensures that this test will succeed. ------------------------------ From: -VIII- Questions on building Tcl and friends on your system Subject: -Q8N- Why can't I print the draft of the Tcl/Tk book? A8N. From ouster@cs.Berkeley.EDU (John Ousterhout): Here's my form letter that seems to explain most of the problems people have had printing parts of the book: Some old versions of the Transcript spooler software cannot properly handle encapsulated Postscript files within another Postscript file when they do page reversal. They tend to garble the page structure of the file, causing an error at the point of the first EPS file. Part II of the Tcl book has lots of EPS files embedded in it, one for each screen dump. If your printer cannot print this file I suggest checking to see if page reversal is enabled for your printer. If so, try asking your local system wizard to disable it for you; this should allow the file to print. Or, find some other way to dump the Postscript file directly to the printer without going through the spooling software (e.g. perhaps you can simply cat it to the printer's serial port). Others have suggested: The embedded pictures have CR as the line separator instead of LF and this may be causing the problem. Try translating them to LFs ... tr '\015' '\012' <book.p2.ps >fixedbook.p2.ps and: This is not the original poster's problem but in countries using A4 paper and on a particular printer, the Dataproducts LZR1260E, the frame size causes the printing to be stretched vertically. This happens with other Framemaker generated documents by the way. A PS interpreter bug no doubt. The fix is to edit the dimensions for A4 paper. This shell script does both fixes. #!/bin/sh cat $1 | tr '\015' '\012' | sed '/FMDOCUMENT$/s/612 792/595 842/' ------------------------------ From: -VIII- Questions on building Tcl and friends on your system Subject: -Q8O- Why am I getting errors on my SGI Indigo workstation? A8O. From Gordon Lack <gml4410@ggr.co.uk> we are told that the SGI c compiler has some bugs with variable arguments. tclVar.c must be compiled with -O0 at IRIX C 4.0.1 because of a compiler bug with varargs. Done by placing specific rule into Makefile. > # GGR SG needs -O0 for varargs at 4.0.1 > > CC_SWITCHES0 = -O0 -I. -I${SRC_DIR} ${AC_FLAGS} ${MATH_FLAGS} \ > ${GENERIC_FLAGS} ${PROTO_FLAGS} ${MEM_DEBUG_FLAGS} \ > -DTCL_LIBRARY=\"${TCL_LIBRARY}\" > > tclVar.o: tclVar.c > $(CC) -c $(CC_SWITCHES0) $< ------------------------------ From: -IX- How, in Tcl, can I XXX: Subject: -Q8P- How do I build expect on Solaris 2.3? A8P. From jra@hrcms.jazz.att.com (Jeff Abramson) we are told that, > using either SunPro cc 2.0.1 or gcc 2.5.8 with > no problems. For SunPro I do: > > CC=cc ./configure --prefix=directory_of_your_choice > make CC=cc > > For gcc I do: > > CC="gcc -fwritable-strings" ./configure \ > --prefix=directory_of_your_choice > make CC="gcc -fwritable-strings" ------------------------------ From: -IX- How, in Tcl, can I XXX: Subject: -Q9A- association lists or property lists? A9A. Use Extended Tcl arrays or keyed lists. For example, if you did a: keylset ttyFields ttyName tty1a keylset ttyFields baudRate 57600 keylset ttyFields parity strip And then an "echo $ttyFields", you'd get: {ttyName tty1a} {baudRate 57600} {parity strip} ------------------------------ From: -IX- How, in Tcl, can I XXX: Subject: -Q9B- call one proc with the multi parameter value returned by another proc? A9B. Assuming y requires multiple args and x returns multiple words, use Tcl's eval command : eval y [x] ------------------------------ From: -IX- How, in Tcl, can I XXX: Subject: -Q9C- pass an array into a proc? A9C. Use upvar rather than try to use global variables when possible. If the function is event driven, you are forced to use global variables. # print elements of an array proc show_array arrayName { upvar $arrayName myArray foreach element [array names myArray] { puts stdout "${arrayName}($element) = $myArray($element)" } } set arval(0) zero set arval(1) one show_array arval To return an array from a procedures, just take the array name in as an argument, as above. Any changes you make in the array will be made in the parent's array as well. Extended Tcl introduces a concept called keyed lists which are arrays made out of lists of key-value pairs and can be passed by value to routines, over networks, etc. ------------------------------ From: -IX- How, in Tcl, can I XXX: Subject: -Q9D- pipe output of a command back into a Tcl parsing procedure? A9D. For example, to grep a pattern out of a range of files, one might do: karl@NeoSoft.com (Karl Lehenbauer) writes: set files [glob /home/cole/stats/*] proc parseInfo { site } { global files # # site is chosen from a listbox earlier # set in [open [concat "|/usr/bin/grep $site $files"] r] while {[gets $in line]>-1} { puts stderr $line } catch {close $in} } One thing: the matching strings are _not_ returned in directory order. But what if I want to check the return code AND use the output of the command? kennykb@dssv01.crd.ge.com (Kevin B. Kenny) writes: if [catch {exec ls} data] { # The exec got an error, and $errorCode has its termination status } else { # The exec succeeded } # In any case, `data' contains all the output from the child process. Note that Karl Lehenbauer adds that errorCode will be a list containing three elements, the string "CHILDSTATUS", the process ID of the child, and the exit status of the child. ------------------------------ From: -IX- How, in Tcl, can I XXX: Subject: -Q9E- merge extended Tcl into other programs such as wish or expect? A9E. The latest version of extended Tcl, tclX 6.7c, has been enhanced to make it easier to incorporate into applications. ------------------------------ From: -IX- How, in Tcl, can I XXX: Subject: -Q9F- delete a procedure from within a script? A9F. rename procedureName "" ------------------------------ From: -IX- How, in Tcl, can I XXX: Subject: -Q9G- get parray to recognize an array variable I have created via upvar? A9G. Right now (June, 1992) upvar doesn't allow you to attach to an individual element of an array. This is considered a bug by Mr. Ousterhout and has been place on a bug list. ------------------------------ From: -IX- How, in Tcl, can I XXX: Subject: -Q9H- get more than 7 digits of double precision ? A9H. In Tcl 6.x, modify the tclExpr.c module to use %lf instead of %g. In Tcl 7.x, set the global variable tcl_precision instead. ------------------------------ From: -IX- How, in Tcl, can I XXX: Subject: -Q9I- grab the command line whenever a non-built-in call is made? A9I. The procedure "unknown" is called automatically with arguments containing the command and its arguments for any command that couldn't be found. In fact, Tcl and Extended Tcl use this feature to provide demand loaded commands, and even entire libraries. So by modifying the unknown procedure you can provide your own extended functionality, or even remove the demand loading capability if you so desire. ------------------------------ From: -IX- How, in Tcl, can I XXX: Subject: -Q9J- get or set an environment variable? A9J. By using something like the following. set olddisplay $env(DISPLAY) set env(DISPLAY) unix:0 Thanks to "Joel Fine" <joel@cs.berkeley.edu> for the answer. ------------------------------ From: -IX- How, in Tcl, can I XXX: Subject: -Q9K- use numbers with leading zeroes? A9K. Dave Morriss was recently having problems because he was trying to do something like: set index [expr [exec date +%W]%[llength $pop_server_list]] but during the 9th and 9th week of the year, he got errors - 08 and 09 are not valid octal numbers in Tcl. Some of the solutions provided were: From George A. Howlett <george.howlett@att.com>, we got: set wknum [format "%g" [exec date +%W]] set index [expr [exec $wknum%[llength $pop_server_list]] From Fred Feirtag <feirtag@wave.nrl.navy.mil> : set index [expr (1[exec date +%W]-100)%[llength $pop_server_list]] From Dan R. Schenck <schendr@Texaco.COM>: set index [expr [string trimleft [exec date +%W] 0]%[llength $pop_server_list]] ------------------------------ From: -IX- How, in Tcl, can I XXX: Subject: -Q9L- find the command line arguments to my application? A9L. If you are using extended Tcl or Expect, you will find the parameters in the Tcl variable argv as a list. Note that in extended Tcl, the name of the program is in the Tcl variable programName and NOT in argv[0]. Thanks to brad@NeoSoft.com (Brad Morrison) and bachww@rtsg.mot.com (Bud Bach) for this answer. ------------------------------ From: -IX- How, in Tcl, can I XXX: Subject: -Q9M- put comments in my script, for example in a case statement? A9M. You can't have comments where you have them. Move the comments inside of the "{" for the case that you want. Your code should read: case 1 { -1 { # # Cannot find information sought # exit 2 } 0 { # # Error in arguments # exit 1 } default { # # Desired information found # exit 0 } } Thanks to gwlester@cpu.com (Gerald W. Lester). ------------------------------ From: -IX- How, in Tcl, can I XXX: Subject: -Q9N- redirect stdin or stdout safely, including binary data? A9N. With Extended Tcl you can safely do stuff like: set infp [open "|compress -dc $fileName"] set outfp [open "|gzip -c $newFileName" w] copyfile $infp $outfp Thanks to karl@NeoSoft.com (Karl Lehenbauer) for the code example. ------------------------------ From: -IX- How, in Tcl, can I XXX: Subject: -Q9O- trap signals, and other more Unix specific functions? A9O. Extended Tcl offers many of these types of functions. For instance, extended Tcl has the 'signal' command: signal action siglist [command] where action is one of "default", "ignore", "error", "trap", "get", plus the POSIX "block" and "unblock" actions (available only on POSIX systems, of course). Siglist is a list of either the symbolic or numeric Unix signal (the SIG prefix is optional). Command is your error handler (or a simple {puts stdout "Don't press *that* key!"} :-) "trap" does what you expect, and I find "error" and "get" to be extremely useful in interactive programs which demand keyboard traversal. Extended Tcl also has things like fork, etc. Answer by brad@NeoSoft.com (Brad Morrison). ------------------------------ From: -X- How, in Tcl, can I XXX: Subject: -Q9P- get quoted strings to work the way I want? A long article dealing with the issues can be found at ftp://harbor.ecn.purdue.edu/pub/tcl/docs/README.programmer Here are some short answers: Q. I'm trying to build up a command for later execution but am having trouble with variable values that include whitespace or special characters. A. The safest way to build up commands is to use the list command so that you can keep track of the list structure. Avoid using double quotes because you can end up with an extra trip through the evaluator. We'll illustrate this with a command to create a button that prints out the label on the button when you click it. Wrong answer #1: button $myname -text $label -command "puts stdout $label" Why? because if $label has whitespace then the puts command will be passed the wrong number of arguments. If $label has $ or [ ] characters, they will be interpreted instead of printed. Good answer #2: button $myname -text $label -command [list puts stdout $label] Why? because list will properly quote the value of $label Q. I'm trying to build up a command for later execution but am having trouble getting some variables to evaluate now, and some to evaluate later when the command is run. A. The cleanest way to do this is to define a procedure that hides the use of the variables at run time, and then build up a call to that procedure using the list command as described previously. (You can even define the procedure on the fly. It will have global scope even it if is created within another procedure.) Wrong answer #1: button $myname -text $label -command \ [list puts stdout $ArrayOfDynamicStuff($label)] Why? The array value will be substituted when the button is created, not later on when the button is clicked. Also, note that the command is executed at the global scope, so it is not necessary to include a "global ArrayOfDynamicStuff" in the command. Wrong answer #2 (backquotes and list): button $myname -text $label -command \ [list puts stdout \$ArrayOfDynamicStuff($label)] Why? Here the list command and the backquote of $ are fighting with each other. The command ends up being something like: puts stdout {$ArrayOfDynamicStuff(foo)} which prevents the substitution of the value of the array element. Dubious answer #3 (backquotes and double-quotes): button $myname -text $label -command \ "puts stdout \$ArrayOfDynamicStuff($label)" Why? This only works if the value of $label has no special characters or whitespace. Clean answer #4 (proc): proc doit { i } { global ArrayOfDynamicStuff puts stdout $ArrayOfDynamicStuff($i) } button $myname -text $label -command [list doit $label] Why? Using little TCL procs for your button commands is a good habit because it eliminates most needs for fancy quoting, and it makes it easier to tweak the button command later on. Q. I'm trying to pass along a variable number of args to another procedure but I'm having trouble getting the $args to expand right. A. Avoid using eval and double quotes because that results in an extra trip through the interpreter. The eval command will do a concat of its arguments if there are more than one, so that pretty much eliminates the need to group things with double quotes. Let's extend the button example: Wrong answer #1: proc mybutton { myname label args } { button $myname -text $label -command [list puts stdout $label] $args } Why? All the extra arguments to mybutton are grouped into one list element that is but into the value of $args. However, the button command expects to see individual arguments, not a sub-list. Wrong answer #2: proc mybutton { myname label args } { eval "button $myname -text $label -command [list puts stdout $label] $args" } Why? The double quotes allow expansion of $label as well as $args, so if $label has any whitespace, the button command will be malformed Good answer #3: proc mybutton { myname label args } { set cmd {button $myname -text $label -command [list puts stdout $label]} eval $cmd $args } Why? Eval will first concatenate its two arguments and then run the result through the interpreter. Think of this as stripping off the outer curly braces from $cmd and $arg and making a single list with all the elements of both. $label will be evaluated exactly once, so the puts command will remain good, and whatever went into args will also be processed exactly one time. Q. Why do I get a syntax error in an if/while/for statement? A. You may have written something like wish: set foo bar wish: if {$foo == bar} {puts stdout bar} syntax error in expression "$foo == bar" in which bar is interpreted as neither a string nor a variable, since strings as operands in expressions MUST be surrounded by double quotes or braces. Change to wish: if {$foo == "bar"} {puts stdout bar} or wish: if {$foo == {bar}} {puts stdout bar} always in expressions, depending on if you want expansion performed or not. Contributed by "Jesper Blommaskog" <d9jesper@dtek.chalmers.se> ------------------------------ From: -X- How, in Tcl, can I XXX: Subject: -Q9Q- share procedures between multiple tcl applications? A9Q. Rather than sourcing the files explicitly, build a tcl library: Step 1. Put the files in a common directory Step 2. Build the tclIndex for the "library". I use a Makefile with a convention like: install.index: (cd ${DESTDIR}/tclscripts/lib; \ echo 'source /usr/local/lib/tcl/init.tcl;\ auto_mkindex . *.tk' | tcl ; exit 0) Step 3. Modify your tcl scripts to reference the library: e.g.: # local additions lappend auto_path /usr/local/lib/tcl_local $env(RDS_TCL_SCRIPTS)/lib Now, as soon as your script tried to reference a procedure in the library, the "unknown" command autoloads the procedure for you. Contributed by Joe VanAndel <vanandel@ncar.ucar.edu> ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q9R- get items inserted into a list? A9R. A user asked why linsert $list 0 .. did not result in .. being inserted into list. d9jesper@dtek.chalmers.se (Jesper Blommaskog) replied: When doing list operations other than lappend, you must save the returned value. This applies to list, lindex, lrange, lreplace at least. In this example, you would perhaps want to do something like: set list [ linsert $list 0 .. ] ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q9S- perform a non-blocking read on a file identifier? A9S. From Frank Smith <frank@arraysystems.nstn.ns.ca> we are told that if you have Extended Tcl, you can read $fileId [fstat $fileId size] This will read only the number of bytes currently available on 'fileId' and consequently will not block. ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q9T- read and write from a pipe without locking up? A9T. The stdio package has an optimization for speed that buffers characters so that you can avoid un-necessary system calls. This isn't very good for interactive use so stdio changes it's behaviour if the file is a terminal. When you write to a pipe you are not writing to a terminal and so your output is buffered, similarly when the program at the other end of the pipe writes its response it is also buffered. The end result is the programs at both end of the pipe stall waiting for input. It is possible to force the buffers to be written using flush in Tcl and fflush() in C, often though, you don't have control over the program at the other end of the pipeline and in that case your only solution is to use a pseudo-teletype (pty). Unfortunately this isn't all that easy. While this isn't directly supported in Tcl the spawn command in expect opens a pty and starts a command. ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.A.1- get my wish application to execute - I just get a wish prompt! Or I just get error msgs about permission denied, not found, etc. A10.A.1. Most systems require a full pathname to the interpreter. So you cannot start a wish script out as #! wish -f Likewise, many Unix systems have a maximum length of characters that you can put on a #! line. If you exceed this, you do not get the behaviour you expect. So do not try to put something like: #! /projects/somethingbig/bin/sun4/wish -f followed by your wish code. Keep the lines short - under 32 characters is recommended. Finally, on some machines, white space after the -f causes a problem. Be sure that the -f are the last characters on the first line of the file. ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.A.2- ,using a machine with less than 8 bit color, run? A10.A.2. Tk doesn't behave very well with less than 8-bit color screens. To try to use it, find all the places in the Tk/wish source where DefaultDepthOfScreen is invoked to test the number of bit-planes. Change all of these to pretend there is just 1 bit-plane, or call a procedure which monitors a Tcl variable so that it is configurable, and you should be okay. Another alternative is to see if the server you are using has alternative visual / color models, such as static visual, etc. One of the alternatives may allow Tk to work better. Thanks to "Nathaniel Borenstein" <nsb@thumper.bellcore.com> for this info! ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.A.3- set X11 resources for a wish application in an app-defaults file? A10.A.3. Read the documentation for the option command. Then you should consider something like the following - assume the program name is xwf. The following are two general purpose functions to put into a library: # envVal envValName # Looks up the envValName environment variable and returns its # value, or {} if it does not exists proc envVal {envValName} { global env if [info exists env($envValName)] {return $env($envValName)} {return {}} } # loadAppDefaults classNameList ?priority? # Searches for the app-default files corresponding to classNames in # the order specified by X Toolkit Intrinsics, and loads them with # the priority specified (default: startupFile). proc loadAppDefaults {classNameList {priority startupFile}} { set filepath "[split [envVal XUSERFILESEARCHPATH] :] \ [envVal XAPPLRESDIR] \ [split [envVal XFILESEARCHPATH] :] \ /usr/lib/X11" foreach i $classNameList { foreach j $filepath { if {[file exists $j/$i]} { option readfile $j/$i $priority; break } } } } # Now, here is what you would put into xwf: option add Tk.BoldFont "*-lucida sans-Bold-R-Normal-*-100-*" widgetDefault loadAppDefaults {xwf XWF} userDefault This sets a program default, then load any defaults specified in the user's default resources and finally any site or general app-defaults resource. Of course, you would want to add some xwf command line handling to allow the user to override things at execution time. ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.A.4- specify bitmap patterns on the command line instead of just as a file name? A10.A.4. You can not, at least as of June, 1992. ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.A.5- get a Motif user interface? A10.A.5. Tk does not currently use the Xt toolkit, so a strict adherence to Motif via the libXm.a routines is not possible. However, the authors of Tk prefer the Motif style of user interface, so you will find that Tk makes quite an attempt to implement a Motif-like interface. ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.A.6- get an OpenLook user interface? A10.A.6. Unfortunately, Tk does not currently use either XView or Xt based widgets in its user interface, so an OpenLook compliant (or even similar) interface is probably not easily achievable in the near future. ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.A.7- get Tk 3.3 to even start - I get security error messages. A10.A.7. Alternate forms of this question often mention that Tk 3.3 send is broken, or ask how to use xauth. Under Tk 3.3, the X11 xauth security mechanism is used. While this provides more security, it does require the user to do a bit more setup. The user needs to create an Xauthority file (typically $HOME/.Xauthority) and then restart the X server with the -auth argument, along with the name of the Xauthority file created. Read the X11 documentation for your system for the details on how to use xauth or comparable software to create the authority files needed. An intro to xauth is available as ftp://harbor.ecn.purdue.edu/pub/tcl/docs/Xauthority . Also note that you can configure Tk to not depend on xauth by modifying the tk3.3/Makefile.in to comment out the following: # To turn off the security checks that disallow incoming sends when # the X server appears to be insecure, reverse the comments on the # following lines: #SECURITY_FLAGS = SECURITY_FLAGS = -DTK_NO_SECURITY ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.B.1- change the default class bindings? A10.B.1. All default class bindings for Tk widgets are initialized in $tk_library/tk.tcl. Use this file as a guide to implement new bindings. For instance, the following code duplicates Button 1's drag-select facility in Button 3 for all listboxes: bind Listbox <3> {%W select from [%W nearest %y]} bind Listbox <B3-Motion> {%W select to [%W nearest %y]} ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.B.2- delete a binding? A10.B.2. Give an empty-string command to the "bind" invocation. For example, to disable the Delete key in all entry fields: bind Entry <Delete> {} ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.B.3- change a binding while it is being executed? A10.B.3. As of June, 1992, this was not a safe thing to do in Tk. It was put on the bug list by John Ousterhout to be fixed in a future version. The solution for now is not to change the bindings, but to change something in the code they execute. For example, keep a state variable that indicates which binding you'd like, but always have the binding call a given procedure. Then that procedure checks the variable and executes one piece of code or another. Or, you could just make the binding's command "eval $cmd" and then change the variable "cmd" depending on your application's state. ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.B.4- bind the arrow key on my Sun keyboard? A10.B.4. You have to call it <Left> rather than <R10>. Under X11, keys are referred to by their keysym. One can use either xmodmap -pk or the xev program to determine what the keysym a particular key on a keyboard is currently generating. If the keysym that is being used is not known by Tk, you may have to edit its ks_names.h file. There is a note in this file that indicates that one should not edit it - but this is where the keysym must be for it to be recognized. Thanks to Wayne Christopher <faustus@CS.Berkeley.EDU> for this note. ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.B.5- get root's mouse bindings to work in my Tk application? A10.B.5. Some window managers, such as mwm, define mouse button bindings which cause Tk some problems. Try saving off the window manager's startup file (something like /.mwmrc for instance) and then copy in a startup file from a login id that works. Thanks to brad@NeoSoft.com (Brad Morrison) for this invaluable tip! ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.C.1- get an application to also use libXt? A10.C.1. Tk2.1 and Xt have different X connections, and XtAppNextEvent will block is there is nothing coming from the X connection. One way of fixing this is get the connection number of Tk using ConnectionNumber(Tk_Display(tk_window)); and using XtAddInput to register this with the Xt event handler. The callback procedure for XtAddInput wrapper procedure that runs Tk_OneEvent(1). There might be problems with Tk file sources which aren't registered with Xt. Thanks to joe@astro.as.utexas.edu (Joe Wang) for this information. ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.C.2- change the X11 cursor? A10.C.2. Here is a tip from mgc@cray.com (M. G. Christenson). Look at /usr/include/X11/cursorfont.h for a list of available cursors. You can use the names in there by removing the 'XC_'. Here's a little proc I use to make my entire application go 'busy' while it's doing something. Just call it with the commands you want to execute, and the watch cursor will be displayed for the time it takes the commands to complete. Note that any new windows will have their normal cursor. proc busy {cmds} { global errorInfo set busy {.app .root} set list [winfo children .] while {$list != ""} { set next {} foreach w $list { set class [winfo class $w] set cursor [lindex [$w config -cursor] 4] if {[winfo toplevel $w] == $w || $cursor != ""} { lappend busy [list $w $cursor] } set next [concat $next [winfo children $w]] } set list $next } foreach w $busy { catch {[lindex $w 0] config -cursor watch} } update idletasks set error [catch {uplevel eval [list $cmds]} result] set ei $errorInfo foreach w $busy { catch {[lindex $w 0] config -cursor [lindex $w 1]} } if $error { error $result $ei } else { return $result } } ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.C.3- raise or lower a window? A10.C.3. This is on the (semi-infinite) list of things to be done in the future. If you have the time, please go ahead and add it and submit the code and all will be grateful. ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.C.4- re-map a withdrawn window id? A10.C.4. Use wm deiconify <windowid>. ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.C.5- use Tk in a subwindow of a non-Tk X11 application? A10.C.5. From faustus@CS.Berkeley.EDU (Wayne A. Christopher): [C]reate the Tk toplevel window but don't map it (wm withdraw). Then re-parent the window to be a subwindow of your other one and then map it. I have done this when the Tk application is a separate process, but if it's the same process I think you will get into trouble with the event loop, since each toolkit wants control. ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.C.6- bind <Enter> and <Leave> to a frame containing other widgets? A10.C.6. From John Ousterhout, ouster@cs.Berkeley.EDU): Each <Enter> or <Leave> event has a "detail" field, which you can access from bindings with "%d". If the detail is "NotifyInferior" it means the pointer has moved into or out of a child window (so it's really still in the area of the window receiving the event). You should be able to check the detail in your scripts and ignore events with a detail of NotifyInferior. Check the Xlib documentation for Enter/Leave events for complete information on the detail field. ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.C.7- mix interactions between Xt and Tk/Tcl? A10.C.7. [From YIP Chi Lap [Beta] <h9118101@hkuxa.hku.hk> ] I have come up with a CPU hogging polling loop that works (till now) for my application which not much direct interaction between a Tk window and an Xt window is made. (e.g., it won't draw something on a Tk window by a Xt-dispatched routine) XEvent xevent; for (;;) { if (XtAppPending(appcontext)) { XtAppNextEvent(appcontext,&xevent); XtDispatchEvent(&xevent); } Tk_DoOneEvent(TK_DONT_WAIT); } [ From David C Mudie <mudie@radon.eecs.berkeley.edu> ] We use the main event loop below. The basic idea is to watch for events arriving from either the Xt server connection or the Tk server connection and then call the library dispatchers. The code fragment below will need to be cleaned up for your usage; there are some missing include statements and global declarations buried elsewhere in the file. /* Allow Tcl/Tk and Xt to work at the same time. */ void tkGo(void) { extern Widget topLevel; int width = ulimit(4, -1); fd_set readfds; struct timeval timeout; int nfds; int tkfd = ConnectionNumber(Tk_Display(mainWindow)); int xtfd = ConnectionNumber(XtDisplay(topLevel)); Tcl_VarEval(interp, "update", NULL); while (1) { /* Select on X server connections to wait for event. */ /* Timeout every half second to allow processing of non-X events */ FD_ZERO(&readfds); FD_SET(tkfd, &readfds); FD_SET(xtfd, &readfds); timeout.tv_sec = 0; timeout.tv_usec = 500000; nfds = select(width, &readfds, NULL, NULL, &timeout); if (nfds < 0 && errno != EINTR) { perror("select"); } else if (nfds == 0) { /* printf("timeout\n"); */ } while (XtPending()) { XtProcessEvent(XtIMAll); } while (Tk_DoOneEvent(1)) { /* do nothing */ } if (mainWindow == NULL) { // Tcl_DeleteInterp(interp); // Tcl_DStringFree(&command); Tcl_Eval(interp, "exit"); return; } } } [ From Davide Frisoni <frisoni@faw.uni-ulm.de> ] One may use Xt properties to communicate between different applications. ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.D.1- resize a listbox? A10.D.1. Use wm min/maxsize - in a uniform manner. Here is a resizable listbox: #!/usr/local/bin/wish -f wm minsize . 20 20 wm maxsize . 1152 900 pack append . [listbox .l -borderwidth 2 -relief raised] {expand fill} Doing the same with the text widget brings its resizing under control too. Thanks to "John C Ellson" <ellson@ontap.att.com). ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.D.2- select two items that are not adjacent in the listbox at one time? A10.D.2. See Marc R. Ewing's Listbox.patch for a way to modify Tk to allow selection of non-contiguous entries. ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.D.3- select items in more than one Tk listbox at a time? A10.D.3. The default for Tk's listbox widget exports its selection as the X selection. There can only be one of these at a time. To turn off this behavior in Tk, use the -exportselection false when you create the listbox. Or, use the option add *Listbox.exportselection false command in the beginning of your script. Thanks to David Herron <david@davids.mmdf.com> for this tip. ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.D.4- avoid fractional white space at the end of a resizable listbox? A10.D.4. First, let's state the problem more clearly. I want to make a resizable listbox and I don't want to constrain it by setting a minimum size. So I pack it with fill expand, I use it to set the grid (so that resizing the window always gives me whole lines) and I set an initial geometry of 1x1 to override the default. However what I get is... (run the code below for a demo and try to resize) listbox .l -geom 1x1 -setgrid 1 -yscrollcommand ".s set" -relief sunken -bd 2 scrollbar .s -command ".l yview" pack .s -side right -fill y pack .l -side top -fill both -expand 1 .l insert end one two three four five six seven eight nine ten "THE END" ...a situation where the partially filled listbox has a blank half-line at the bottom even if there are more items in the list. This is very confusing because it fools the user into thinking that there is nothing else beyond what's visible. Why does it happen? Now for the answer. Look at the window as it is created, before the resizing. See that poor, tiny little scrollbar squeezed in that microscopic window? It, too, requests a minimum size, and it so happens that the starting geometry for the listbox (i.e. the situation referred to as "1x1") receives some free fractional space at the bottom. And you never get rid of it, since the resizing is constrained to be in whole characters. The thing to do is to define the initial layout in such a way that the widget that has -setgrid actually displays an integer number of lines and columns. In the above example, setting -geom 1x2 does the trick. Thanks to Frank Stajano <fms@cam-orl.co.uk> for this tip. ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.E.1- get output from a Tk canvas? A10.E.1. The latest Tk has a save suboption on canvas which allows one to create a file describing the canvas. The default output is Encapsulated Postscript, but there is an xpm3 suboption as well. ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.E.2- fill a canvas which is bounded by lines as opposed to a shape like a polygon, oval, etc.? A10.E.2. No, you have to at least use a polygon if you want to fill an area bounded by some lines. ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.E.3- raise/lower canvas window objects or draw graphics onto a window object inside a canvas? A10.E.3. You can't yet. "Jesper Blommaskog" <d9jesper@dtek.chalmers.se>. ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.E.4- detect when the canvas has been resized? A10.E.4. From Nathaniel Pryce <np@hpl.hp.co.uk>: > I have a window with a canvas containing some stuff that logically > fills the canvas (say, a chess board or a map of the world). I want > this toplevel window to be resizable and of course, when the win is > resized, I want the stuff inside the canvas to be scaled > accordingly. Now, I can manage the scaling of the stuff, but what > I'm having trouble with is DETECTING that I should do it. How can I > be notified that the window has been resized? Nat's answer is: You need to bind a command to the Configure event, like this: proc config {w h} { puts stdout ".canvas - width = $w, height = $h" } bind .canvas <Configure> "config %w %h" .canvas - width = 224, height = 251 .canvas - width = 224, height = 151 .canvas - width = 224, height = 243 # and so forth ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.F.1- get the name of my own interpreter? A10.F.1. george.howlett@att.com (George A. Howlett) points us to the winfo manual page - winfo name . gets the name of the current application. ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.F.2- get -relief to work on my text widgets? A10.F.2. From Owen Rees <rtor@ansa.co.uk>, we find out that we must: "[m]ake the border width non-zero as in" text .t -width 20 -height 20 -relief sunken -borderwidth 4 ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.F.3- create a scrollable window of buttons? A10.F.3. There are at least two ways to do this. First, there is a hypertext widget that one can get from the Tcl User Contributed Code Archive - (see "tcl-faq/part4") and (see "tcl-faq/part5") for details - which provides such a facility. And here is some sample code from "Michael Moore" <mdm@stegosaur.cis.ohio-state.edu> which shows a way to do this using just Tk. #! /bin/wish -f # # This demonstrates how to create a scrollable canvas with multiple # buttons. # # Author : Michael Moore # Date : November 17, 1992 # # # This procedure obtains all the items with the tag "active" # and prints out their ids. proc multi_action {} { set list [.frame.canvas find withtag "active"] puts stdout "Active Item Ids : " foreach item $list { puts stdout $item } } # # This simulates the toggling of a command button... # Note that it only works on a color display as is right now # but the principle is the same for b&w screens. # proc multi_activate {num id} { set tags [.frame.canvas gettags $id] if {[lsearch $tags "active"] != -1} { .frame.canvas dtag $id "active" .frame.canvas.button$num configure \ -background "#060" \ -activebackground "#080" } else { .frame.canvas addtag "active" withtag $id .frame.canvas.button$num configure \ -background "#600" \ -activebackground "#800" } } proc setup {} { frame .frame scrollbar .frame.scroll \ -command ".frame.canvas yview" \ -relief raised canvas .frame.canvas \ -yscroll ".frame.scroll set" \ -scrollregion {0 0 0 650} \ -relief raised \ -confine false \ -scrollincrement 25 pack append .frame \ .frame.scroll {left frame center filly} \ .frame.canvas {left frame center fillx filly} pack append .\ .frame {left frame center fillx filly} button .frame.canvas.action \ -relief raised \ -text "Action" \ -command "multi_action" .frame.canvas create window 1 25 \ -anchor w \ -window .frame.canvas.action for {set i 2} {$i < 26} {incr i} { button .frame.canvas.button$i \ -relief raised \ -background "#060" \ -foreground wheat \ -activebackground "#080" \ -activeforeground wheat \ -text "Button $i" set id [.frame.canvas create window 1 [expr $i*25] \ -anchor w \ -window .frame.canvas.button$i] .frame.canvas.button$i configure \ -command "multi_activate $i $id" } } setup ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.F.4- pack a text widget so that it can be resized interactively? A10.F.4. From Spencer W. Thomas <spencer@med.umich.edu> we find that we need to: wm minsize . 0 0 text .text pack append . .text {fill expand} ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.F.5- create a widget with an upper case name? A10.F.5. During a recent revision of Tk, things were changed so that names beginning with a capital letter are reserved for class names. Specific instances of widgets must begin with a lower case letter. This enables X11 resource definitions to distinguish between a class and instance. ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.F.6- create equal sized buttons? A10.F.6. Recently, Micael Salmon <etxmesa@eos.ericsson.se> posted: In article <1993Jun23.065417.4302@ericsson.se>, I write: |> I am currently working on yet another tn3270 emulator and I have run |> into a problem with creating equal sized buttons. I have created an |> array of buttons for PF and cursor keys and I would now like to make |> them all the same size. Arranging them into columns was not |> a problem but when I add bitmaps the buttons lose their horizontal |> alignment. What I tried was to read the height and width of the buttons |> using winfo, determine the largest and then use pads to force them to |> be the same size, this doesn't seem to work. The technique of using |> pre-set height and width doesn't seem applicable when using a mixture |> of bitmaps and text as the size in pixels of a text button is font |> dependent. All suggestions welcome. Jim Wight <J.K.Wight@newcastle.ac.uk> suggested using reqheight and reqwidth and then specifying padx and pady in the pack command for each button. Jim says: I think it only fair to point out that it was Tuomas J Lukka <lukka@klaava.Helsinki.FI> who suggested the use of reqwidth and reqheight when I asked how to get over the deficiencies in my first attempt at a solution that I posted to this group. Since you're all agog I might as well post the final solution (more or less) that I mailed to Michael. frame .frame1 frame .frame2 button .frame1.a -text "pretty long button text" button .frame1.b -text "short one" button .frame2.c -bitmap "@/usr/include/X11/bitmaps/xlogo32" button .frame2.d -text "tiny" set long [winfo reqwidth .frame1.a] set short [winfo reqwidth .frame1.b] set medium [winfo reqwidth .frame2.c] set tiny [winfo reqwidth .frame2.d] set pady [expr [winfo reqheight .frame2.c]-[winfo reqheight .frame2.d]] pack append .frame1 .frame1.a "filly pady $pady" pack append .frame1 .frame1.b "fillx padx [expr $long-$short] filly pady $pady"pack append .frame2 .frame2.c "fillx padx [expr $long-$medium] filly" pack append .frame2 .frame2.d "fillx padx [expr $long-$tiny] filly pady $pady" pack append . .frame1 {left} .frame2 {left} ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.F.7- vertically stack radio buttons aligning regardless of font? A10.F.7. Till Brychcy <brychcy@informatik.tu-muenchen.de> provides the following example: radiobutton .times -text Times -anchor w radiobutton .helvetica -text Helvetica -anchor w radiobutton .courier -text Courier -anchor w pack .times .helvetica .courier -side top -fill x Note that you are using anchor west in the widgets themselves, and not in the packer. This lets the packer produce full width buttons. ------------------------------ From: -X- How, in Tk, can I XXX: Subject: -Q10.F.8- initialize an entry widget with some text? A10.F.8. kesch@kappco.kapp-coburg.de (Peter Kesch) provides us with one example: set default "foobar" entry .foo -width 25 -state disabled -textvariable default ------------------------------ End of comp.lang.tcl Frequently Asked Questions (2/5) ***************************************************** -- :s Great net resources sought... :s Larry W. Virden INET: lvirden@cas.org :s Personal: 674 Falls Place, Reynoldsburg, OH 43068-1614 The task of an educator should be to irrigate the desert not clear the forest. -- :s Great net resources sought... :s Larry W. Virden INET: lvirden@cas.org :s Personal: 674 Falls Place, Reynoldsburg, OH 43068-1614 The task of an educator should be to irrigate the desert not clear the forest.