Updated 2017-07-25 09:30:10 by rz

How to post on this page  edit

Please do not edit this part, it is meant as a guide!

Page contents

This page runs the risk of being deleted and corrupted. Please be very careful when editing it. If you inadvertently delete it, immediately revert your edit using the History link on the left side of this page.

Do NOT attempt to restore it by copying and pasting the text from a previous revision, or all page formatting will be lost!

Please put new questions at the TOP of the page, below this section, so that as the page grows longer, new questions are seen first.

Also please put a section header on top of every question and put two stars in the beginning of the title and two stars in the end. This will make your question's section easily editable.

Once you have received a satisfactory answer, please cut your question and answer directly on an appropriate page of the wiki. If you cannot find an existing page, create a new one.

You might also simply want to put a hyperlink leading to a page of the wiki where your question is included like Didier has done on February 5th 2011. This will save you the trouble of cutting your question to an existing page afterwards.

Put your question below. Thanks!

Questions  edit

Need help evaluating a CSV type file

[SSSS] 2017-07-14 Let's first start with some data
0,           0.000,           0.000,           0.000,           0.000,           0.000,           0.000
3, 6271268.071, 258945.242, 179.607, 0.6,179
3, 6271132.546, 259078.095, 178.556, -0.4,179
0, 0.000, 0.000, 0.000,
5, 6271760.120, 258421.555, 175.902, -0.1,176
5, 6271758.291, 258426.387, 175.789, -0.2,176
0, 0.000, 0.000, 0.000,
0, 0.000, 0.000, 0.000, END

I am writing this to be executed by a third party program "Surpac" and would like to read the file (.str string file - native to Surpac. Basically a text comma delimited file) and write each line to a separate file based off the fifth variable. So far I have something like this, but really I'm just lost.
set a [open "temp_170714.str" r]
set lines [split [read $a] "\n"]
close $a;
foreach line $lines{
        set y [
        if {expr variable5<-0.3} {
                      set filename "Fill.str"
                      set fileId [open $filename "w"]
                      puts $fileId $data
                      } elseif {expr variable5>0.3} {
                                          set filename "Cut.str"
                                          set fileId [open $filename "w"]
                                          puts $fileId $data
                                          } else {
                                                  set filename "Ongrade.str"
                                                  set fileId [open $filename "w"]
                                                  puts $fileId $data

Can someone please point me in a direction <>^v?!?

Also the;
0, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000

0, 0.000, 0.000, 0.000,
0, 0.000, 0.000, 0.000, END

Should be in every file. Surpac for string file.

RZ try this:
set fd [open temp_170714.str r]
set myLines [split [read $fd] \n]
close $fd
set fd1 [open Fill.str w]
set fd2 [open Cut.str w]
set fd3 [open Ongrade.str w]
puts $fd1 "0, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000"
puts $fd2 "0, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000"
puts $fd3 "0, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000"
foreach myLine $myLines {
  set myVars [split $myLine ,]
  if {[llength $myVars] != 5} continue
  set myVar5 [string trim [lindex $myVars 4]]
  if {$myVar5 < -0.3} {
    puts $fd1 $myLine
  } elseif {$myVar > 0.3} {
    puts $fd2 $myLine
  } else {
    puts $fd3 $myLine
puts $fd1 "0, 0.000, 0.000, 0.000,
0, 0.000, 0.000, 0.000, END"
puts $fd2 "0, 0.000, 0.000, 0.000,
0, 0.000, 0.000, 0.000, END"
puts $fd3 "0, 0.000, 0.000, 0.000,
0, 0.000, 0.000, 0.000, END"
close $fd1
close $fd2
close $fd3

new question

wdb Strange behaviour: the command wm iconify takes two seconds, and the command wm deiconify does not work at all.

My workaround: first wm withdraw the window, then wm deiconify. My OS is Linux.

Any suggestions?
% info patchlevel
% package require Tk
% puts [clock seconds]; wm iconify .; puts [clock seconds]
% expr 1494964634-1494964632
% # two seconds used for iconify
% wm deiconify .
% # no reaction, window stays iconified
% parray tcl_platform 
tcl_platform(byteOrder)     = littleEndian
tcl_platform(machine)       = i686
tcl_platform(os)            = Linux
tcl_platform(osVersion)     = 3.19.0-32-generic
tcl_platform(pathSeparator) = :
tcl_platform(platform)      = unix
tcl_platform(pointerSize)   = 4
tcl_platform(threaded)      = 1
tcl_platform(user)          = wolf
tcl_platform(wordSize)      = 4

Static Code Analysis Tool

[Chris_b] 2017-04-27 Hi there, We are developing using TCL and were looking for a static code analysis tool. More specifically to achieve what CheckMarx and Fortify do for their supported languages. Obviously Unit tests are covering the part of missing/deleted code and preventing bad commits/typos etc but is there anything that we can consider as appropriate

Suported Languages for Checkmarx and Fortify

Thank you

bll 2017-4-27: I liked tclcheck, and prefer it to Nagelfar. Unfortunately, I have not made time to work with tclcheck as much as I would like.

[Chris_b] 2017-4-27: Well unfortunately i'm mainly interested for security related analysis like a tool that can identify known code vulnerabilities (XSS Attacks, SQL injection etc), that could potentially apply coverage of security standards like (OWASP Top 10, SANS 25 etc)

[VIVEK] 2017-04-17: Is there a easy way to navigate the TCL code base for large software projects which have object oriented functionality using SNIT. I tried using CTAGS, but I am not able to find the right way of giving the correct options to the ctafs. Thank you.

MG 2017-03-30 Does anyone have any up-to-date pre-built Windows binaries for tls? teacup only lists up to, and the official site at https://core.tcl.tk/tcltls/wiki/Download only has a source archive, no binaries.

split out token and background edit

gold 25MAR2017, I have loaded Sumerian counting board on this wiki and need help splitting out Value and background tokens. The token symbol and token background are created with canvas text, then the tokens are retagged both with rand number tag and token worth tag to move jointly. With the logic on color (gold color), I trying to drop the worth_token ( value eg, 3600,60,1,1/60) on the background tokens. I only want to count value tokens, otherwise get twice the value. The logic on the color is sticking or evaled as zero. Can somebody help out with some ideas to negate the worth($tag) on the token background? Thanks in advance.
                    set tilename  [expr {int(rand()*1000000000.)}]
  # .cv itemconfigure token  -tag [concat mv xdat_$x  ydat_$y obj_$tilename # $worth($tag) value_$worth($tag) ]
 .cv itemconfigure token  -tag [concat mv xdat_$x  ydat_$y obj_$tilename # $worth($tag) value_$worth($tag) colorxit_[.cv itemcget $item -fill]  ]   
           #.cv itemconfigure token  -tag [concat mv xdat_$x  ydat_$y obj_$tilename  ]
                 if {[.cv itemcget $item -fill] == "gold"} { .cv itemconfigure token  -tag [concat mv xdat_$x  ydat_$y obj_$tilename colorxit_[.cv itemcget $item -fill]  ]    }     

[Sumerian Counting Boards, multiplication operation placement strategy, and eTCL demo example, numerical analysis]

Signing a JWT header for Google OAuth2 (again)

nurdglaw 2017-03-06: I've seen the page Signing a JWT header for Google OAuth2 but I can't get the code there to work.

  • Google now recommends that you download your information as JSON. The above page assumes that it's in a .pem file. A little searching suggests strongly that the JSON data keyed by private_key is the content of a .pem file. The openssl utility appears to confirm this.
  • The private_key data is wrapped in -----BEGIN PRIVATE KEY----- and -----END PRIVATE KEY-----. Using pki version 0.6, the pki::pkcs::parse_key routine seems to expect it to be wrapped in -----BEGIN RSA PRIVATE KEY----- and -----END RSA PRIVATE KEY-----.
  • Even after I change the private_key data so that it's wrapped appropriately, pki::pkcs::parse_key $private_key throws an error - Expected Integer (0x02), but got 30.

So, either I need to supply a password, or I have to do something completely different.

If I need a password, where do I get it from? Google doesn't mention one when downloading service account information as JSON. If I should be doing something different, then what?

Thanks in advance.

PS - Sorry if this should go on the above page - please reply there if appropriate and remove this question from here.

Different behavior of scale in 8.6.6

[beppe] 2017-02-19: On initialization, scale widget executed command callback while in 8.6.6 it does not. Since my code is running on machines with different TCL/TK versions I am struggling to find a good solution for everything. The code to reproduce this behavior is:
set sliderValue 50
pack [label .l1 -text "Init"]
proc onChange {sliderValue} {.l1 configure -text $sliderValue}
pack [scale .s1 -variable sliderValue -command onChange]

At beginning, the label will be "Init" in 8.6.6 and "50" in previous versions. I did not find any mention of this change in the documentation.

MG Assuming that this is your actual use case, and not just a simplified demonstration, you can do away with the proc entirely, by changing the label to
  label .l1 -textvariable sliderValue

The docs for the scale command say that the -command is invoked "whenever the scale's value is changed via a widget command", so I wouldn't expect it to be run when the widget is initially created. I am still seeing that behaviour in Tk 8.6.1, though, so if it's not happening in 8.6.6, it may be a more recent bugfix. Googling for "Tk Changelog" brings up so much out of date crap that I can't find any actual recent changes at a glance, though, so I couldn't say for sure.

[beppe] 2017-02-19: Unfortunately my callback function is much more complex, I cannot solve my problems as you indicated. I used that example just to highlight the different behavior of TK versions.

In the meantime I found the following in the summary of 8.6.6 changes:

* Fix: circumstances of command callbacks from scale.

But I was not able to find a description of the "circumstances". At the end I need to fix my code in a way that will behaves in the same way for 8.6.6 and previous versions.

MG There are a couple of things you could do, then; add something like
if {[package vcompare [package require Tk] 8.6.6] >= 0} {
  onChange $sliderValue;# invoked automatically for versions prior to 8.6.6

to manually invoke the command for 8.6.6+. Or you could replace your scale call with
pack [scale .s1 -variable sliderValue]
.s1 configure -command onChange
onChange $sliderValue

That way, it will never be automatically invoked on widget creation, and you'll be manually running it every time.

EMJ The change was quite possibly this: http://core.tcl.tk/tk/info/2262543

gold Many complex math programs have either initialize, refresh, or reset routines to force correct behavior. Most of my canvas programs on this wiki have this feature (on changing labels and resetting variables prior to calculations). Where the program defaults and canvas colors/features/clear displays are reset prior to (push button) calculation. This tactic should work across TCL versions, at least in the several versions I test (eTCL,TCL8.5, and TCL8.6).
 ::ttk::button .test4 -text "Testcase3" -command {clearx;fillup 120. 12.0 15.0 1.  1.  1. 1. 104.0 }
  button  .b3 -text "castle"   -command {clrcanvas .cv;barley .cv 20; castle  .cv; }
  button  .b8 -text "S.board"   -command { refreshgridx .cv  }

[beppe] Thanks MG and EMJ, I find it pretty weird but I'll probably go conditioning my code to the TK version used as suggested by MG. If the change is related to what EMJ pointed out, the fix is addressing an issue raised in 2008! I am not able to judge if this was, or was not, a real bug, however I wonder if this fix is worth breaking the compatibility with previous versions. Something to ask elsewhere ;-)

need help on Field Expansion subroutine

gold - 2017-01-20 On the this tcl wiki, the code in Field Expansion calculator is working when solution approachs the answer from below the desired number, but the solution needs to approach correctly from either below or above the desired number. This routine is sort of like a double barreled newton's method from Square Root, especially proc SqrtB {num} {# Newton's method}. Wrote a test console program for a field_expansion_procedure at bottom of wiki page. Can someone help or load corrected code for the console program at bottom of page. I am drawing a mental blank. Babylonian Field Expansion Procedure Algorithm and example demo eTCL calculator, numerical analysis

gold15feb2017. question answered, program seems to be working if spaghetti code.

treating extended lines with pretty print

gold - 2017-01-20 I have been using ased editor for some code on my wiki pages. When the tcl lines with extended lines and empty lines are indented, the code is garbled/will not compile. Can someone direct me to a PC based editor that will handle extended lines or help me clean up some of my wiki pages in their own editor? Thanks in advance.Refrigerator_Pinyin_Poetry Random Poetry Chalkboard Chinese Xiangqi Chessboard has extended and empty lines.

gold15feb2017. maybe question answered, wiki page ASED has been updated

Ms windows exec and paths with embedded braces

[TomT] - 2017-01-09 18:58:57

I have been trying for several days to pass a native file name (MS windows) with a path component of {...} through the exec command. I always get "extra characters following a close brace". Is there a bit of magic I am missing here? (MS windows commonly uses GUIDs enclosed in braces as path names.) As near as I can tell the exec command reduces all backslash sequences to one or zero backslashes. That makes it impossible to have a backslash protected character after a file path separator. Here a simple test case:
exec cmd.exe /c echo {c:/to/{left}/and right}

[??] 2017-01-09 21:00:00 ?? please id..

A example with env and winword.exe
eval exec  {$env(ProgramFiles)/Microsoft\ Office/Office14/winword.exe}  &

exec {*}[auto_execok start ]  echo  {c:\tmp\Neuer Ordner}

[Tom T] 2017-01-10 11:19:30

Those examples do NOT exhibit the problem which seems to be caused by the following sequence in a parameter "\{" where as "\a{" seems just fine. We can shorten the example to:
exec {c:\foo\{bar}\x} 
extra characters after close-brace

exec {c:\foo\a{bar}\x}
couldn't execute "c:\foo\a{bar}\x": no such file or directory

The second has a correct file name, i.e. what was asked for.

[gre] 2017-01-10 21:19

a path and a file

C:\tmp\12{abc}\a b\test.bat
set x 12{abc}
exec {*}[auto_execok cmd.exe] /C [file join  c:/ tmp  $x "a b" test.bat]

MG On Windows 7, I made a file called {test}.txt in my E:/ drive, then did:
% file exists [file join E:/ "{test}.txt"]
% exec [file join E:/ "{test}.txt"]
couldn't execute "E:\{test}.txt": no such file or directory
% exec {*}[auto_execok start] [file join E:/ "{test}.txt"]

The second exec worked fine; I'm guessing the error message from the first is misleading, and just means that there's no executable file found.

The reason for your 'extra characters' error was that your \ is escaping the inner opening brace, so the inner closing brace is ending the arg, and then the \x} after is unexpected. It works fine if you double the backslashes, or just use forwardslashes. (But you'll still need to use auto_execok start unless your file is a .exe or something else executable.)

Tcl/Tk program crashes on Exceed

[Jack] 2016-12-05:

I recently got a Open Code program that crashes on a Linux system when I select a file in an Open dialog box, and the end result is a "Bad Window" error. I am accessing the Linux system through a Windows PC on my desk through Exceed, and am fairly certain the problem is somehow related to this method of access - If I run the program directly on the Linux system (not from my PC through Exceed), it runs fine. Unfortunately, this is not an option here as a work around, so I have to get the Exceed problem fixed. Is anyone familiar with this (I'm sure not!) - Any help would be greatly appreciated. Thanx!

MG You're likely going to need to give a lot more information. What's the program you're running? A quick google suggests Exceed is some form of X forwarding (over ssh?); what exactly does your access of the Linux system look like? What's the full error message; can you screenshot it?

I am running a Freeware program supplied by NASA as an engineering tool - I'm not a programmer, so most of this is unfamiliar to me. However, I was able to do a little sleuthing and determined the line where the failure occurs. The line is:
    togl $dw -width $Pref(dw,wwidth) -height $Pref(dw,wheight) -rgba true -double true -depth true \ -ident Box2 -overlay $overlaybool

And the error message I get is:
    Error of failed request:  BadWindow (invalid Window parameter)
Major opcode of failed request
3 (X_GetWindowAttributes)
Resource id in failed request
Serial number of failed request
Current serial number in output stream

The version of Tcl/tk I'm running is 8.5.8. My access to the Linux system is through a Windows PC, but once Exceed starts it "looks" like a Linux terminal. The version of Linux is Red Hat v6.0, and although it's an X Windows platform, I invoke the offending program via a command line interface. I'm not sure if all that matters because as stated, it runs fine if I log directly in to the Linux system without using Exceed.

Thanx A MILLION for your help!!!!! :-)


AM (2016-12-06) The problem may be that togl is an interface to OpenGL and that eXceed is missing the necessary packages that enable the interaction between X11 and OpenGL. However, I am not an expert - perhaps better to ask on comp.lang.tcl.

AMG: Are you able to run other OpenGL/3D programs? Try "glxgears" for example. I'm wondering if your version of Exceed doesn't support OpenGL. You might also try other X servers for Windows such as VcXsrv [1] in place of Exceed, used in combination with PuTTY [2] for remote terminal access and X forwarding.

This may be the case, but it may be subtle. I do have OpenGL, and I am successfully running GUI's in Matlab 2016a, which I know for a fact addresses OpenGL. Our OpenGL is software (I guess that makes a difference since I had a problem with Matlab in the beginning because of that, but the fix was really simple such that even I could understand it). I say it's subtle because the program that I'm having problems with is able to open a fileopen dialog box, and it functions to the point of me being able to drill down through directories and select an input file. After that point, the program crashes at the "togl" line. Also of note - I did set a debugging flag, which sends some output to the command screen, and it does successfully echo back the name of the input file I pick from the dialog box. Does that help...?

Package origin

lm 2016-10-25

I have several instances of a same package. Is there a simple way to know from which directory the package loaded after package require comes from ? One way may be to do the same job as package require does, and outputting the instances in the order they appear with version ... This may be the aim of a new package command ?

MG There is:
set package "http"
if { ![catch {package require $package} currver] } {
  foreach ver [package versions $package] {
    puts "$ver: [package ifneeded $package $ver"

Produces output like this for me:
2.8.7: package provide http 2.8.7;source -encoding utf-8 C:/Tcl/lib/tcl8/8.6/http-2.8.7.tm
1.0: tclPkgSetup C:/Tcl/lib/tcl8.6/http1.0 http 1.0 {{http.tcl source {httpCopyDone httpCopyStart httpEof httpEvent httpFinish httpMapReply httpProxyRequired http_code http_config http_data http_formatQuery http_get http_reset http_size http_status http_wait}}}

If you just want the version loaded and not info on all available versions, package ifneeded $package $currver instead of the foreach will work.

Formatting Label

Beware 2016-10-21: I'm looking for a quick way to add bold/italic options to a label. I can't see anything already created on the wiki. using an HTML widget seems a little overkill. Any ideas?

--If the text doesn't have to change, how about using an image? Beware The text is configurable by the user...

MG Do you want all the text in bold/italic, or just some? If you want all, it's just a matter of configuring the -font option ($label config -font [list Arial 12 "bold italic"]). (For ::ttk::labels, it's a bit trickier, as they're not very user-friendly to get from the default.) If you just want to format specific words/parts of the label.. that's not so easy, and you might need to use multiple labels or a text widget pretending to be a label, or something like that.

Beware I want some sort of mini markup so certain words can be bold/italic. I'll leave it for version 2 of the script and probably switch to text. Thanks.

MG 2016-10-08 - A few people have reported getting an error message on my bundled Tcl app saying, 'You can’t use this version of the application "XXX" with this version of macOS' after a recent OS update was released. I don't have a Mac myself (the bundle was put together for me by someone else) so can't test things. Does anyone know the cause/solution? Thanks.

gold2016-06-01. cancel following, found my answer on busted computer,2016-06-03r. Did somebody happen to save an old (~~2014) copy of Sumerian Coefficients in the Pottery Factory and Calculator Demo Example on their backup drive or distribution cd-tape. Some of my offline images and my ACER laptop died but I was able to replot some on my home computer. I was unable to grab the images with the many archaic kiln styles and the double chamber kiln. Is there someway to grab an html copy on the wayback machine? thanks.

Picture loading

gold1may2016, can someone load jpg TkReverse screen into TkReverse TkReverse? getting spam alerts.thanks

Multiple windows

[Cockneyjock] 2016-04-12:
Hi again.
I need to create a GUI with several windows. I have searched and Googled but cannot get a definitive answer.
Do I ...
(a) create all of the Toplevels in one file? It would be huge!
(b) Create separate files for each Toplevel (preferable) and, if so, how do I open the different windows?
(c) Create separate 'programs' and somehow 'launch' them on a button press?
(d) Give up the whole idea and go out and cut the grass ;o)

Each window will probably call a dialog or a sub-window

Any advice and/or sample scripts would be more than welcome.


bll 2016-4-12
(b) You can do: source fileB.tcl for each file. You would have to be very careful with your variable names and namespaces.
(c) This works fine. exec fileC.tcl to launch. I use this method and sockets to communicate between the processes.
(d) Always works. You can use multiple windows to look at the grass.

[Cockneyjock] 2016-04-26:
Hi bll,
Sorry for the delay but I have been involved in some urgent Basic programming but I'm still keen to learn Tcl :o)
On the serious side (there's not much grass here in spain) (c) seems to be the best solution for me. If I 'exec' another file will the first script wait for the other script to finish or can I just close file 1 before opening file 2? You can do it both ways in Realbasic.
Thanks for the help

AMG: [exec] is an awfully big hammer to drive in this thumbtack of a problem. You say your desire is to divide a large program into multiple files. That's what [source] is for. Just remember that (by default) everything will live in the same namespace and interpreter, so take care that the names don't collide. If that is a problem, Tcl supports multiple namespaces per interpreter and multiple interpreters per process.

If you use [exec], you'll have your multiple files (good), but you'll also have multiple processes which means needing to take on the challenge of interprocess communication.

bll 2016-4-26: You'll have to tell us more about what you are doing. If your different toplevels are independent programs and don't need to communicate with each other, then [exec] is fine. Otherwise you will want to look into [namespace] and [source] or [package] in order to split up your code. As AMG says, managing multiple processes and the intercommunication can add a lot of overhead.

exec will wait for the other script to finish.

[Cockneyjock] 2016-04-28:
Hi guys.
The only thing that my program will need to share amongst windows is the client ID. Each window will perform a different task on the client record or a task not specifically related to the client but is, for example, an accounting task.

I have been looking at the examples provided by GRIDPLUS and this seems to solve the need for many of the individual windows by using notebook pages for add and edit etc.,

It seems to me that I can write the ClientID to a database or .ini file and transfer it between source files; so I will work towards that method.

As always, thanks very much for the responses. I am supposed to be 'retired to the Sun' but I am busier than ever;o)

The problem is that over the years my brain has filled up and there is not much space left in the memory banks for all this new data.



gold 1may2016. Possibly, multiple frames for separate program screens could solve your problem, as opposed to multiple windows. The kingdom Game kingdom of strategy and other calc demos have multiple frames for separate tasks (eg. display canvas, list of buttons, text entry, and report text in separate frames). 4 or 5 frames could display 4 or 5 canvases for many separate programs. I think the multiple frames could incorporate separate source tcl files as necessary, to make things more complicated enough.

Am I an idiot??

[Cockneyjock] 2016-03-12:
I have read all the online tutorials and still can't get my head round how to compile the tcl and td sources.
My latest attempt on Windows 7 involved downloading the XP virtual PC and creating a new VS6 install thereon.
Whether I use the makefile.vc or the dsw in VC6 it still gives me errors which I don't understand. Can anyone point me to an idoits guide
or a walkthrough so that I can see where I am going wrong ... and yes, I have set up the environment.
Any help will be greatly appreciated. CJ.

MG Any particular reason you need to compile it yourself, instead of downloading ActiveTcl or a TclKit to use?
[Cockneyjock] 2016-03-13:Hi MG, I have an existing program that is written in a version of Basic and I want to convert it to cross-platform.
Tcl has been suggested and I have 'played' with ActiveTcl. However, my program runs stand-alone from an SD card and so I will have to 'wrap' the
script to get an executable. I don't think I can do that with ActiveTcl. I am not sure what TclKit does - I'll investigate later but am out today
to the Reus (Spain) classic car show. I just wish I could afford to buy one ;o) CJ

MG Ahh, I see. There's actually no need to compile Tcl yourself for that. There are a couple of ways you could go:

  • Just put your Tcl script on the SD card, and rely on the host having a copy of Tcl that you can use to run the script.
  • Put a TclKit or ActiveTcl basekit on the SD card for each platform you want to run on, along with your Tcl script, and run the script with the appropriate executable on each platform
  • Or, if you don't want to include the raw Tcl script on the SD card, make a Starpack, which is basically a Tcl runtime executable and your Tcl script bundled into a single file. You don't need to compile Tcl yourself, just use the sdx tool to bundle them together. See How to create my first Starpack.

TclKits and basekits are just pre-compiled, single-file runtimes which can be used either as stand-alone Tcl interpreters or for creating Starpacks. Some just include Tcl or Tcl/Tk, and some are compiled with other extensions included.

[Cockneyjock] 2016-03-13: Thanks for that MG, I'll have a play with the options to see what is best for me

Is there a pre-compiled kit that includes the SQLite library. My program is a bespoke appointments system and uses a lot of database access.

By the way, the car show was good and certainly worth a visit.

MG I'm not sure, off the top of my head, but the basekits page lists a few different builds and the extensions built into them. However, you can bundle the extension inside your starpack (the same way you include your Tcl script), and Tcl can load it from there, so it shouldn't be a problem if there isn't.

[Cockneyjock] 2016-03-14:
Thanks MG, I was working through some other web pages last evening and saw a way to bundle the sqlite into the Starpack. It looks like the way to go
All I have to do now is get my head round the geometry and re-design the pages. Don't we have fun!
Once again, many thanks for the advice.

snack compilation Problem

nscerqueira 2016-03-05: see snack compilation Problem

problems with openbox

[tomwildturkeyranchnet] 2016-02-29: In a quest for a simpler window manager I (up?)dated to 'openbox'.
The issue I am having is with buttons with bitmaps being rendered as a black blob.
This only happens when either pack or grid expands the button to fill the space.
It also seems to be dependent on the colors (and seems to some how redefine what given colors refer to).
Aside from preventing expansion by pack or grid, is there another way to fix this?
(For an example of this see filerunner on sourceforge)

AMG: I'm not aware of Openbox having any connection to Tcl or Tk. Why are you asking your question here?

EMJ 20160301 : but filerunner is a Tcl/Tk application. I have fetched the OP's version and it starts and looks OK with twm as the window manager (that's what I use and I don't have any others installed). Tried in any other window managers?

Multiple levels of variable substitution?

[B-Unit] 2016-02-24: Is there a way to perform variable substitution on a variable whose name is itself specified by variable substitution?
For instance, if I make a list and then name it using "${x}list", is there a way to get at the items in that list without having to type out the value of x manually? Basically, $(${x}list)), except that doesn't actually work.

HJG You found how do i do $$var - double dereferencing a variable, deref and array get/array names ?

Alternative bindings for buttons

HJG 2016-02-23: I want a button that does different things on left/middle/right-click, or when pressed with shift or control.

The manual on buttons mentions that it is possible to change the default-bindings, but gives no example.
Has this been done yet ?

APN Just use the standard bind command like for any other widget.
bind .b <Shift-Button-1> YOUR-SCRIPT

HJG Thanks!

Missing Category "Tcl syntax help"

for example, in source and string totitle.

AMG: This page used to exist and serve as a quasi-category page listing all the core Tcl commands, script variables, and shell environment variables, plus a few other useful references. See the last such version here: [3]. The page was deleted because it duplicated the Tcl Commands, Tcl syntax, tclvars, and Magic names pages, but the references were not cleaned up. I don't think it was a good idea to delete it, so I will reinstate it as a collection of links to pages about Tcl syntax help.

rename wiki-pages

HJG 2016-02-19: Is is it possible to rename wiki-pages, without loss of history ?

I would like to rename [String Manipualtion Functions] --> String Manipulation Functions.

AMG: Copy the contents of the old page to the new, and include a link to the old page's history somewhere in the new. I just did this for the pages mentioned above.

Spam detected on user-page / false positive

HJG 2016-01-27: I edited a section of my userpage on this wiki today, and got this message:
  Edit/Upload of type 'text/x-wikit' on page 14271 - HaJo Gurt
  Your changes have NOT been saved because they are considered SPAM.

I'm pretty sure there is no spam on my page. So, what triggered that message ?
Also, doing the same edit on the whole page was accepted without error when saving.

The page has a lot of links, but mostly to pages within this wiki. So I guess the heuristic to detect spam is way off...

PYK 2016-01-31: Efforts to counter the current spam attack are ongoing. Your report will make it to the right people. Stay tuned.

stevel 2016-02-01: I've tweaked the filter, your home page should be OK from now on.

HJG 2016-02-02: The problem is still present - see my latest changes to section "Demos & Placeholders", which has only internal links.

stevel 2016-02-02: I won't go into the details of how the spam mitigation works (because I don't want to alert the spammers) however lots of empty links in a page can trigger a false positive. Please send me a copy of the rejected page text via email and I'll tweak the filter again. I apologise for the inconvenience, we'd rather not have false positives but we certainly don't want the spam.

HJG Here is an easy testcase:
edit section Bughunting, with one existing line, with link to existing page, adding "the": rev 69-->70 is considered spam.
Doing that edit on the whole page is accepted. Do you really want that via eMail ?

Another easy testcase: edit section Test, one link to existing page in this wiki, rev 72-->73 is considered spam.
The previous content, with the link to my own page, was accepted.

Regarding the current wave of "Call Us"-spam today, with no links in their text, from [email protected] :
  Edit summary
   , Wed Dec 31 19:00:00 EST 1969, New page

The creation-date for that page looks quite wrong.

Also, the IP-addresses shown are wrong too. This has been going for some weeks now.

HJG 2016-02-10 .. 2016-02-19: The problem persists - see [database configure] (only one internal link).

How do i get the parent directory if the path containing . or .. without expanding symlinks?

AMG: Question moved to [4] - file normalize.

tkImg serious bug under Aero and workaround (seems to be solved with the tkImg Build 1.4.5

MiR: 2016-04-18: Got a message from SF Buftracking, the Aero bug in tkImg seems to be solved with the 1.4.5 release of tkImg. Tested my application and it runs like a charm. Hurray!

MiR: 2015-12-25

I ran into a well known bug of Img in conjunction with Aero/WindowVista and above. (https://sourceforge.net/p/tkimg/bugs/67/ reported already in 2010)

I was even able to reproduce this under WINE and there it was consistent in all Windows versions, so maybe Aero is not the only reason for the glitch. Since this bug makes it impossible to export a canvas to an image I'm looking for a workaround, since I try to use the script on both OS. My prog is losely based on http://wiki.tcl.tk/15611 an I try to save the content to a JPG file. Any thoughts on this? Any help is appreciated, since I don't really want to go the route via postscript.

Update to TK spinbox ?

[mocallins] 2015-11-22:

Add a configuration option to place the up/down buttons, on the other side, of the entry box. And/or even place the buttonup, on top of the entry box, and the buttondown, on the bottom.

Inspecting a pixel within a canvas

[IanMacUK] 2015-11-01:

I was attempting to be clever and use the shapes provied by canvas in tk to construct a mask which I could then inspect thus saving me writing a load of code to fill rectangles and closed polygons.

Below is some very simplified code.
# so I create a window with a shape on it which has been filled
toplevel .mask
wm title .mask "Geology mask"
set mask2 [canvas .mask.c -width 1023 -height 253]
.mask.c create rect 30 10 120 80 -outline #fb0 -fill #fb0
pack .mask.c

# what I wish to do now is inspect each pixel of the window .mask.c and see if it has the colour #fb0 
# if it does I want to manipulate an image which I have also loaded into another window.
# I can easily access each bit of the image and modify as if required.

set fn "Overview_swath_1.v3.rc.png"
image create photo myPng -file $fn -palette 255/255/255
toplevel .png
wm title .png  "Overview swath 1"
pack [label .png.l -image myPng ]

set x 2
set y 2
set pix [myPng get $y $x]

So how do I inspect my canvas pixel in a similar manner?

With thanks in advance.

aspect 2015-11-02: the best way I know is by making an image from the canvas contents and querying that for pixel values:
update  ;# the the canvas has to be mapped + rendered first
image create photo canimg -format window -data .mask.c
puts [canimg get $y $x]

This may not play too well if the canvas is partially obscured -- something from here might point towards a solution if that is the case. I'd also like to mention CRIMP if you find pixel-by-pixel operations from Tcl too slow, and can use a binary extension in your application.

HJG 2016-01-27: See also Get the color of the pixel under the pointer.

In Windows platform when i click on dialog box Icon on taskbar is not supported to open, but it works fine in UNIX .

[Kalavathi] 2015-10-08: I am facing the issue both using "transient option with wm command" and grab command. To reproduce the issue i will send some code
toplevel .child
frame .child.frame
button .child.frame.button -text "child" -command "destroy .child"
pack .child.frame.button
pack .child.frame

toplevel .parent
frame .parent.frame
button .parent.frame.button -text "parent" -command "destroy .parent"
pack .parent.frame.button
pack .parent.frame

wm transient .child .parent
grab .child
wm withdraw .

When i execute above code , two windows opened child and parent.To minimize this windows i have used keybord shortcut "windows+d". To open this windows when i try to click icon on taskbar, i am not able to open. To open this window, i have to select "Bring to Front" related menu in Windows Task Manager.

can you give me the solution by using transient and grab features to the child and parent windows.

ffidl - problems with char parameter

[Boltar] 2015-09-07: I'm using ffidl the first time and have a little problem with char arrays. Example C function declaration:
long myVersion (char Versioninfo[257])

Where Versioninfo is an out parameter.

My first ffidl approach:
package require Ffidl
set DLL some.dll
ffidl::callout _MyVersion {char} long [ffidl::symbol $DLL MyVersion] stdcall

set szMyVersion        [binary format [::ffidl::info format char]257 [lrepeat 257 0x00]]
set result [_MyVersion $szMyVersion]

But this does not work. The ErrMsg tells me, that the function expects an integer.

So I changed the callout to a pointer.
package require Ffidl
set DLL some.dll
ffidl::callout _MyVersion {pointer-utf8} long [ffidl::symbol $DLL MyVersion] stdcall

set szMyVersion        [binary format [::ffidl::info format char]257 [lrepeat 257 0x00]]
set result [_MyVersion szMyVersion]
binary scan $szMyVersion a* szMyVersion

This time the function does not run into an error and also returns 'OK', but the variable szMyVersion is still filled with 257 0x00. I tried different pointers (pointer-var, pointer-obj etc.), but I'm not able to read the version string.

I guess, that I'm not seeing the woods for the trees. Additionally, what would be the right way for using the above mentioned parameter as an in/out parameter (an other function is defined like this)

Thanks in advance.

different behavior when serial port connection is scripted

[tnteverett] 2015-08-06: When I connect to a serial port manually, then power on the device, then wait for characters to appear, I can type a few carriage returns to make the connection detect the baud rate and start sending and receiving characters. When I script this sequence, it appears that I cannot duplicate the autobaud by sending carriage returns when I detect the first few characters on the serial port. Has anyone ever run across this issue or have any suggestions on how I can debug the failure?

AMG: Just a guess, but maybe your script isn't entering the event loop. I dunno. Can you post some sample code?

LWS: My guesses are (a) your script is running faster than human interaction, giving the stream less time to synchronize. Who/what is doing the baudrate detection? Try using the after command to insert a delay to simulate human-like interaction. (b) Depending on how you constructed the string you are sending out (with the carriage returns), you may need to use flush on the stream.

Send a get request to google.com using http please help

[sam] 2015-08-5:

I have a question. I am trying to send a get request to google.com using tcl. How would I do this?

MG There are a number of ways. The simplest is probably to use the http package; documentation and an example are here. TclCurl would be another possible way.

tk - copy/paste vs. disabled

[Wurzelsepp]: in old versions of Tk, one could disable an entry (or text) after inserting data, but still copy/paste from these fields. Is there a way to achieve to allow copying with current tk version?

aspect: I don't know about the old Tk behaviour, but read-only text widget has some examples - I like the snit rotext version linked from there.

MG Use $widget -state readonly

[Wurzelsepp]: thanks a lot, I have changed all my entries to -state readonly (if running on a new interpreter), and things look fine

Beginner needs help with writing a script

[wizzleteats]: I'm just a beginner in TCL creating some of my first scripts. I'm not a programmer. I have the script (example below) to create new IDTL lines in a Genband switch. It works great but only if I start at 1 and increment by 1 from there, 220 in the example below. I want to be able to start at a higher number, let's say 1101 and increment by 1 up to 1200. Does anyone have any idea how to do that? I can't seem to figure it out.
source /generic/scripts/libsource.tcl
libsource_source libstd.tcl

say "Building your new IDTLs now.  Please Stand By..."

while {1} {
   ovly cpk
   for {set i 1} {$i < 220} {incr i} {
      cmd "new idtl plsd ide 1 $i spl"
   cmd "****"

Siqsuruq - 2015-06-29 16:07:42

[try this:]
source /generic/scripts/libsource.tcl
libsource_source libstd.tcl

say "Building your new IDTLs now.  Please Stand By..."

while {1} {
   ovly cpk
   for {set i 1101} {$i < 1200} {incr i} {
      cmd "new idtl plsd ide 1 $i spl"
   cmd "****"

Rendering of link-names for links to archive.org

HJG 2015-06-19: There is a problem with links that have an embedded "http", such as those you get from the waybackmachine:

It would be nice if someone could look into repairing the rendering of version 'C2' above.

AMG: I tried to file an issue report at https://code.google.com/p/wikitcl/issues/list but the database is currently read-only [6]. Here's the text so I can paste it later when (if?) Google Code is back online.
The Wiki text:

https://web.archive.org/web/20150530232011/http://www.graphviz.org/%|%link name%|%

renders as:

https://web.archive.org/web/20150530232011/link name%|%

The text "https://web.archive.org/web/20150530232011/" is a link to same.  The text "link" is a link to "http://www.graphviz.org/".

Reported by HJG.  See http://wiki.tcl.tk/_/revision?N=37862&V=40#pagetoc232136cb for more information.

HJG 2015-06-21: The same type of problem shows up when the link-name contains links, such as

Why are we still using Google Code?

AMG: Google Code is being retired, and we MUST move elsewhere [7] within the year.

HJG 2016-01-27: has this problem with Google-Code been taken care of yet ?

Table of Contents in historical wiki pages

AMG: (Posting here since I can't post to the Google Code issues list. To be moved later, I hope.)

When looking at historical revisions of a wiki page, e.g. [8], the Table of Contents is not emitted. This makes it hard to produce links to sections of historical pages. The requisite id attributes tags are emitted, so such links work, but they have to be made by hand. This can only be done if the current version of the page has section titles with the same name so the proper anchor checksum is produced.

What are we doing with issues, anyway?

AMG: For the past few years, there doesn't seem to have been been any activity addressing issues on the issues list [9]. Is anyone maintaining the wiki code?

Broken images

HJG 2015-05-20: There are a lot of wiki-pages with broken images,
because external links have expired (many of them from user gold). Does the wiki have a way to check for this, and make a list ?

gold1may2016,Thanks for your help in restoring offsite images. I'm going to cut many of my references to offsite images. Can't easily retrieve some images and not sure images add that much. I'll restore my offsites into onsite WIKI storage, what I can. Would like some posted (approved consensus) specifications or suggestions of image type (png or gif) and usefull byte size on the how_to page. Since have seen arguments on use of jpegs and fuzzies on TCL WIKI. There are some search key words that will pull the older images.

Preferred Online-Interpreter

MiHa 2015-05-17: I made a page about Online-IDEs / interpreters with Tcl-support,
and would like feedback and recommandations, such as

  • What else are out there, what are their advantages / disadvantages, etc.?
  • Lua has its own Live demo, but Tcl doesn't have such a thing ? Why ?

Date for announcements on startpage of wiki

MiHa 2015-05-05: Why is there no date on news-items like "Tcl/Tk 8.6.4 Released" ?

[Shikiria] - 2015-04-28 02:18:52 - wm maxsize

I have made a little GUI and its max size is -800 -400.
wm maxsize . 800 400

Now when I maximize my little window it jumps to the top left hand corner. Is there a way for me to make it maximize on the spot?

With the window maximized and it's sitting on the top left hand corner, if I try to grab the title bar and move it to the center, the window immediately minimizes again.

Is there a way to prevent that?

Thanks for the help guys.

Warm regards Shikiria

arjen: The purpose of wm maxsize is to restrict the size of the window. From your description I read that you want it to fill the screen anyway.

In that case, just drop wm maxsize, in which case Tcl/Tk calculates the size of the window itself. You can be quite lazy in that respect.

Wiki - Links to questions

MiHa 2015-04-27:

At the top of Ask, and it shall be given # 8, there is the statement

"Please add hyperlinks leading to your question at the top of this page".

Isn't that the job of "<<TOC>>" ?

Wiki - Section edit

MiHa 2015-04-25:

This wiki shows edit-links only for sections of level 1 (header enclosed in **). Can this be controlled somehow ? For example, in these "Ask"-pages, it would be nice to be able to only edit the section of a single question (that is, a level 2-section).

PYK 2015-05-17: This is one reason I keep the pages I've edited mostly flat, rarely going beyond the ** header level. Sometimes I think it's a good thing that it isn't easier to use multiple layers of headings, because it encourages keeping each page smaller and moving sections off into their own pages. In general, I think keeping each wiki page smaller and more dedicated to a particular issue is good style.

String-to-integer / values from clock

MiHa 2015-03-15 : This problem came up when writing FuzzyClock, converting values from clock seconds to integer.

What is the preferred way to convert the string-values for hours, minutes or seconds to integers ?
There are several "obvious ways" to do it, such as

  • incr mm; incr mm -1;
  • set x [expr {$mm}]
  • format %u $mm
  • and more, see expr problems with int.
  • All those work "most of the time", but give a surprising error for some values, e.g. "08" and "09".

For FuzzyClock, I wrote a proc s2i, that just special-cases these values, but there should be some better way.

RLE (2015-05-19): Use the scan command:
  % scan "2015-09-08 07:06:05" "%d-%d-%d %d:%d:%d" y mo d h m s
  % foreach var {y mo d h m s} { puts "$var=[set $var]" }

MiHa: That is a neat solution, thanks !

Image placement / TOC

MiHa 2015-03-14 : I think it would be nice to have a picture on the right side of a <<TOC>>, where the space is mostly unused. I tried that on the Graffiti-page, but it doesn't come out that way.

Using a table doesn't help in this case, because it appears that <<TOC>> only works when standing alone on a line.
What are the options for placing images here on the wiki ?

Edit very first section of a page

MiHa 2015-03-14 : The **first section** gets number 0, so how can you edit the top section only, of a (possibly very long) page ?

AMG: When you originally make the page, start it with a **whatever** section header, saying "overview" or some such. It's not ideal, I know, but it's what we have right now.

LAM 2015-01-19 02:36:03

«Once you have received a satisfactory answer, please cut your question and answer directly on an appropriate page of the wiki. If you cannot find an existing page, create a new one.»

Sorry but i think is better avoid this kind of pages of miscellaneous. If the people cut the questions after receiving an answer, why are these pages are full of questions ? (isn´t for lack of anwsers, sure).

[BW] 2015-01-20 02:36:03:

It is because we, ticklish world Tclers are not as disciplined as Ticklish Argentinian Tecklers! :-) We don't put the paragraph in the right spot when the paragraph is complete. If we did so, this page would serve its purpose: to be a temporary repository of questions and answers. Oh well!


MiR - 2015-02-25:

I'm working with jEdit mainly. Is there something like a codefolding sidekick for Tcl (as for other languages like php, where I can see the functions in the sidebar)? I've been searching for a time now and can't find any... thanks for your help, Michael

RLE 2015-02-25: I've heard it said that the Geany editor will display Tcl procs in the sidebar.

I am working on a simple Expect/TCL Script. In my output, I am seeing that my script however is sending on involuntary command, which I have not even set. Please take a look at the code and let me know your output using the debug option. I can see clearly in my debug options that expect sends a command which I did not trigger, and I know this because the expect debug outtptut does not show "send: sending " before sending the command. Please test out this script, let me know your experience, and if you can, show me your output. Thanks, seriously. The source code is below: (If you try out the code, don't forget to add the #!/your/shell at the top)

Driver Script : driver.sh

echo "Please enter your Username" #Prompt user for Username read -s username echo "Please enter your Password" #Prompt user for Password read -s password echo "Starting Expect Script" ./sample.expect $username $password

Expect Script : sample.expect
 exp_internal 1
 set username [lindex $argv 0]
 set password [lindex $argv 1]
 set hostFile [open hosts.txt r]
 while { [gets $hostFile hostname] >= 0 } {
 spawn ssh -q -o StrictHostKeyChecking=no $username@$hostname
 expect "password: "
 send  "$password\r"
 expect "$ "
 send "pbrun /bin/su -"
 expect {
  "^" {
   puts "NewLine Was Caught After pbrun /bin/su - command"
  "Rejected.*" {
   puts "NewLine & Return Carraige Was Caught After pbrun /bin/su - command"
 send "hostname\r"
 expect {
  -re {".{8}[0-9]{5}"*} {
   puts "BUFFER::REFFUB"

Hostfile : hosts.txt