Version 20 of Tcl Questions and Answers

Updated 2007-03-15 18:33:20

Purpose: Area for questions regarding tcl, tk and its extensions, plus answers from the community.

See Beginning Tcl, Beginning Tk and Advanced Tcl as well as Ask, and it shall be given.. You might also find that the Tcl Developer Xchange Site's General Tcl Q&A message board [L1 ] is of use and/or interest.

Also, the Tcler's Wiki chatroom and comp.lang.tcl are two additional useful sources for getting questions answered.

Finally, many tcl applications and extensions have some sort of web site presence - often with forums or mailing lists for handling of specific questions.


Are there any of the questions below which could/should be spun off into their own page?


I've been asked to generate a tcl window without the maximized option available. To remove the icon completely. In Practical Programming in Tcl and Tk, by Welch, it states that dealing with maximized is not available up to tcl8.2, but may be in future releases. I'm lost but still hopeful. Any hints or direction would be greatly appreciated.

The hint is this. The option to change the size of the window to the maximized size is not something controlled by an application. Instead, it is a function of the window manager. It is not possible to turn just that feature off. At best, you can, however, use

      wm overrideredirect $window

That removes the title bar along with its decorations. Also take a look at Catching Window Managed Events.


I need to know more about Tk Tables, if anyone has any documentation on them it would be great!

LV: I don't see a signature on the above, so I don't know who to address the answer to. But if you are talking about things like spread sheets, then http://www.purl.org/net/hobbs/tcl/capp/ has a nice TkTable extension. Is there additional information you need?


I am extending Tcl with an application where ideally I would like to add to the meaning of operators such as =+-*/ in user input to a Tk interface e.g I want the user input of

   z = x + y 

to be translated into a Tcl expression such as

   Type -this [set z [$x add $y] ]

where Type is a command I have defined which has an operator add defined and x, y and z are instances of Type.

Is there a parser which I could use to do this translation?

The underlying C++ classes are interfaced to Tcl using Swig.

Thanks - JPF

DKF: I'd be strongly inclined in this sort of situation to use a YACC/bison parser (spit out a suitable Tcl script into a string that you pass back) in this case, using Swig to join it in to the main Tcl executable. The usual reason for not going for this sort of thing is that you don't want the overhead of having your own custom C code, but you've got all that already so this restriction doesn't apply... :^) It is certainly pretty easy to hack something together with an LALR(1) parser generator, provided you're not after robustness (just remember to sort out the reduce/reduce conflicts and you'll be OK) because that takes a lot more effort.

Alas, I don't have any suitable example code to hand. There is some (highly atypical) YACC input (part of the [clock scan] implementation) in the Tcl source distribution though; look for a file ending in .y in the generic directory (I don't remember its exact name...)

Thank you for this.

Overhead does not matter as this is intended for an educational tool which will spend most of the time waiting for the student to respond. I have found it very easy to use Swig to bring in more and more C++ code and also generate good documentation at the same time.

As I am new to Tcl, and bewlidered by all the different addons which exist, I was rather hoping that someone could point me at some source code (C or Tcl) which I could make use of. JPF

I'm not aware of any parser generators for Tcl (there might be some in the Tcl FAQ, but I'm not up to searching that mighty document right now) since most Tcl scripters use Tcl to do their parsing (and Tcl is one of the few languages which is not really LALR(1) or LL(k).) - DKF

Thanks for this. I've had a look around on the Tcl-FAQ and found the following.

ftp://ftp.procplace.com/pub/tcl/sorted/packages-7.6/devel/tyacc-0.9.tar.gz

I dont know if this is a help to me or not. I also don't know what LALR stands for and can find no other reference to it in this Wikit. JPF

DKF: LALR(1) and LL(k) are styles of parser. (YACC-derivatives are LALR(1).) The kinds of languages that the two are capable of recognising are slightly different, but I'm not a good-enough compiler expert to tell you the difference, except to say that rules need to be right-recursive with one style for efficiency, and left-recursive with the other...

hi, i got trouble in the attribute of frame --- geometry.

i look at the man page of frame, and there is no geometry, but i do see some tcl use -geometry, such as

frame .buttonBar \

    -background {#186e75} \
    -borderwidth {2} \
    -geometry {656x67} \
    -relief {raised}

the OS is redhat 7.2, and i install tcl-8.3.3-65, tcllib-1.0-65, tclx-8.3-65.


In order to use geometry, which tcl interpreter I should use, or do I need to install some pack?

You can mail to mailto:[email protected]

Is editing this page the way to ask a question? It is a little strange. hope i did not do wrong. - RS: No, you found the right way ;-) The "-geometry" attribute is indeed not defined for frames, nor is it a standard option. Maybe this is very old Tk (before 4.0)? The _x_ pattern seems to indicate both the width and height values. So if you replace that line with

 -width 656 -height 67 \

it should work on contemporary Tk. (But try also to omit such explicit pixel dimensioning, and see how the geometry manager figures the geometry out - often better, and more portable, than we humans do ...)


Question 28/11/2002 Hi all, I'm a very new tcl user (I started this morning!). My question is the following: I want write a proc that can accept an argument, but this argument can be omitted so a default parameter must be used. Problem is that my proc (proc nam {var} {......}) doesn't works if parameter is omitted! Thanks in advance!


RS: Arguments that are a list of two mean that the second element is the default, if the argument is not given on call:

 proc demo {{arg default}} {return $arg}
 % demo hello
 hello
 % demo 
 default

It surely would be useful if someone would migrate answered questions from pages like this, or

and integrate questions/answers onto relevant pages, leaving a hyper link title behind. Hopefully, this would result in an easier to see set of unanswered questions...


Category Community Category Discussion