''This page has had numerous incidents 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'n'pasting the text from a previous revision, or all page formatting will be lost!'' !!!!!! '''Please add hyperlinks leading to your question at the top of this page.''' <
> Also consider putting a **section heading** on the top of each new question. <
> And of course, please put new questions at the '''TOP''' of the page, so that as the page grows longer, new questions are seen first. !!!!!! Once you have received a satisfactory answer, ''please'' put your question and answer directly on an appropriate page of the wiki (if you cannot find an existing page, create a new one). And of course, please put new questions at the TOP of the page, so that as the page grows longer, new questions are seen first. Afterwards, remove the original question and answer and leave a hyperlink here (as [ARA] has done on May 2 2009); this way everyone will know who needs help. This page could then act as a sort of reference page for questions asked by the Community - sort of ''Who has asked what and when''. Thanks for your help. * '''Started on:''' 2009 May 02 * '''Ended on:''' 2011 February 5th (Saturday) ---- ** Entry with progress bar as background ** Hello, Is it possible to create with Tcl/Tk an entry with a scrollbar as a background? One can see such a thig in e.g. Windows 7, adress entry of windows explorer: http://www.meshparts.de/pict/entry-progressbar.jpg Thank you very much. Best regards Alex [AMG]: You may need to fabricate your own using the [[[canvas]]] widget. Put text on top of a rectangle. I warn you, it may be tough to get all the bindings right. You might also research how [Ttk] is implemented; there could be some clues in there. ---- **couldn't open socket: connection refused** (Question regarding AIX that was inserted here on 2012-08-30 moved to the current Ask page, at [http://wiki.tcl.tk/28825#pagetocd317cfde].) **linsert in recursive lists** Hi all, I have written a code to get the index of recursive lists: ====== set a {a b {c {d e}}} %proc List{list_name {prefix {}}} { set end_point [expr [llength $list_name] -1] for {set start_point 0} {$start_point <= $end_point} {incr start_point} { if {[llength [lindex $list_name $start_point]] == 1} { puts "Index for [lindex $list_name $start_point] is $prefix$start_point" } else { append prefix $start_point List[lindex $list_name $start_point] $prefix } } ====== Now in this i want insert some elements inside, how can i do that. Eg: This is how the program should look like ====== puts "Enter element" gets stdin el { user enters as 4 } puts "Enter insert posittion" gets stdin ind { user gives as 210} ====== So if 210 index is valid in the list the new element should be inserted and if the user gives ind as something like 530 it should display "error in index entered".. How can i do this? Please help. Thanks in advance [gold]16jun2011, Ask9 has question on nested list input also. Maybe combine q&a? Found refs. [list level], discussion in [linsert] and [lset] See section on list in http://en.wikibooks.org/wiki/Tcl_Programming/Introduction. Really asking for lset with multiple index. ====== console operation % set test {{a b} {c d}} {a b} {c d} % lset test 1 1 x {a b} {c x} % lset test 1 1 { x gosh} {a b} {c { x gosh}} if { [ lset test 1 1 2 3 4 x ] != 1 } { error " index level not found" } console returns "list index out of range" ====== [jbr] - Here is a similar strange command I created just a little while ago. Maybe there should be a general discussion on commands that build data structures and need list variable semantics with multiple indices? ====== proc dict-lappend { dict args } { upvar $dict D set keys [lrange $args 0 end-1] set value [lindex $args end] if { [info exists D] && [dict exists $D {*}$keys] } { dict set D {*}$keys [list {*}[dict get $D {*}$keys] $value] } else { dict set D {*}$keys [list $value] } } ====== ** Shutting down a virtual machine by ssh'ing into it via Tcl/Expect ** [sg332] 2011-012-06 I am trying to shutdown down a Virtual machine by ssh'ing into it via Tcl/Expect. At the point after I send "yes\r" using the send command in response to a confirmation request of my earlier shutdown request, sometimes I find a print out of just "y" and expect times out while waiting for the follow-on shutdown confirmation. Can someone help with a solution/workaround asap? I assume, send was not able to flush out the remaining characters for some reason to the Linux box. The Tcl/Expect script is on a Linux machine. [RLE] (2011-02-06) Are you ssh'ing into another Linux based system? If so, any reason you can not just use "shutdown -h now" to shutdown immediately without asking any confirmation? [sg332] (2011-02-07) Thanks for replying. Good question. The reason is I want to gracefully shutdown the box, which means applications on that remote machine should shutdown gracefully before the OS starts shutting down. A OS platform command that I am using allows me to do so. But for that, I have to ssh into the platform using platform credentials. ---- ** Finding a way to have the 'alt' (and 'default') [Ttk] themes ttk::checkbox display their indeterminate state when the widget variable is undefined** [peterc] 2011-01-25 I'm trying to find a way to have the 'alt' (and 'default') [Ttk] themes ttk::checkbox display their indeterminate state when the widget variable is undefined. It works on Windows but not in these themes. It seems that the indeterminate state image has either never been set or has been set to the same image as "off". I'm hoping the fix is something I can put at the start of my own scripts (after package require Ttk), rather than being an edit in Ttk's source, so I don't have to update Ttk's source every time I update Ttk. I'm happy to run up my own indeterminate state images, assuming that's part of the solution. ---- **Difference in the types of objects returned with 'array get' when moving from 8.4 to 8.5** [JonC] Jan-21-2011 In moving from 8.4 to 8.5 we see a difference in the types of objects returned with 'array get. The otype command returns the typePtr->name from the object (based on the Islist c code from the wiki). ====== array set arr [list a 1 b 2 c [list 3] d [list 4 5]] puts "from array" foreach a [array names arr] { puts "[otype $arr($a)] $arr($a)" } puts "from get" foreach a [array get arr] { puts "[otype $a] $a" } ====== In 8.4.9 the values in the array retrieved with 'array get' are still lists. ====== % load otype.so % source check_array.tcl from array list 4 5 none 1 none 2 list 3 from get none d list 4 5 none a none 1 none b none 2 none c list 3 % ====== In 8.5.1 they turn into strings when using 'array get'. ====== % load otype.so % source check_array.tcl from array list 4 5 none 1 none 2 list 3 from get none d none 4 5 none a none 1 none b none 2 none c none 3 ====== Why does this happen? In our actual application we have other object types some of which may be expensive to construct. -------------- EDIT: It didn't timestamp my edit, so I'll add it below manually. ---- ** Question regarding lappend's adding the bounding braces to each list element ** 2011-12-01 LtDrebin I have a simple question regarding lappend. In the following script: ====== set c varia[34]ble set p [list] set pins "YC YE" foreach pin $pins { lappend p $c/$pin } ====== an echo $p will display the following: {varia[[34]ble/YC} {varia[[34]ble/YE}. Why is lappend adding the bounding braces to each list element? I want the output to be: varia[[34]ble/YC varia[[34]ble/YE The variable c has brackets around the 34. It is being interpreted as an image link here. I have also tried setting each new element to variable p as a separate variable and then appending just that variable, but I get the same result. I have a workaround to this using concat, but I'm curious as to why lappend is behaving this way. It seems that the brackets in the variable c are causing this. If c only has a slash in it, for instance, it seems to work correctly. My workaround, fyi: ====== set c varia[34]ble set p [list] set pins "YC YE" foreach pin $pins { set p [concat p $c/$pin] } ====== [MG] Is that exactly the script you're using? For me that results in an 'invalid command name "34"' error in the 'set c ..' statement. But, ignoring that (and assuming you're actually escaping them there, with set c {varia[34]ble} set c varia\[34\]ble or something similar), lappend isn't really adding curly braces - they're simply displayed in the string representation of the list. ====== % set c {varia[34]ble} varia[34]ble % set p [list] % set pins "YC YE" YC YE % foreach pin $pins { lappend p $c/$pin } % set p {varia[34]ble/YC} {varia[34]ble/YE} % lindex $p 0 varia[34]ble/YC % join $p " " varia[34]ble/YC varia[34]ble/YE ====== Using [join] creates a "true" string from the list, which doesn't include the curly braces (which are used only to denote/escape the individual list elements, as they contain special characters). {gwm} also "lindex $p 0" and "lindex $p 1" return the 'true' elements of the list without the {}; any operation (such as foreach part $p {...}) which uses the list will then use the form you expected for each element of the list. {LtDrebin} I'm running these scripts inside of a microchip development tool. It uses tcl for user-level scripting. I have tried both escaping the brackets and not, and setting the varaible works just fine. I'm guessing that our tcl shell has some sort of protection for brackets, as many of the instances in a microchip have all sorts of symbols used in their names. It's probably more efficient to use lappend, then? I might have to use the entire list p as an argument in a later function. In that case, it will still keep the bounding braces. The function can handle that (I think), but it's not what I intended and I'm a perfectionist, dammit! When I use the command set c varia[34]ble, the console of my tool gives the message: []'s in strings are used to invoke sub-functions, escape []'s or use {}'s to define the string. I understand that, but running echo $c shows that c was set correctly. In my script, c will be set by a foreach statement, where c is an individual element of a list of all sorts of c's. The only way I can see to "properly" set c using {}'s would be to scrap the foreach and just iterate through the list of c's. {LtDrebin} I'm running into more problems with lappend adding extra braces to list elements. My script has a lot of nested loops and so I'm a bit concerned about runtime. I read that using lappend is more efficient than using concat to append elements to a list. If I use concat via the workaround above, the list does not contain extra braces (well, so far...). So, I have a few options on how to remove these braces for future operations. 1) Use the \[concat\] workaround. 2) After lappending everthing, use \[join $list\] to convert it to a string with spaces in between. This seems to remove the extra braces and retains the list elements. 3) Whenever I need to call an element of the list, use \[lindex\] or \[lrange\] (haven't tested lrange yet). As for the reason why lappend is adding the extra braces, I think it's because the tcl parser is using braces in strings with brackets to keep the parser from substituting results of the bracket phrase, which might be seen as a command. [gwm] You might also like to experiment with append - this is like lappend, it adds at the end of the string, but is pure string. To retain the 'list-like' behaviour you need to put 'append p " new\[34\]bit", like this: ====== foreach pin $pins { append p " $c/$pin" } puts $p ====== -------------- ** Major memory leak bug in TclOO ** 2011-02-01 [gwm] memory leak bug in TclOO (cured by 12 Feb 2011). I have created the following minimal demo of TclOO which creates one object, then uses its only method 6 million times. ======== console show ; update # make it an O-O program using oo:: package require TclOO oo::class create cell { # a general cell. method setcp1 {vv} {my variable cp1;set cp1 $vv} } set a [cell new] ;# create just one object! set i 0;while {$i<6000000} { incr i; if {!($i%25000)} {puts "Looped $i times";update} $a setcp1 123 } # NB $a destroy did not free the memory ======== After 6 million operations using Activestate's 8.6.0.0.b4 I had gobbled about 400MB (by just ONE TclOO object). Memory was still gobbled if you remove the "my" variable method setcp1 {vv} { variable cp1;set cp1 $vv} But it was not gobbled if no variable was declared. method setcp1 {vv} { set cp1 $vv} [MS] just ran this on HEAD/linux and does not see anything untoward [GWM] DKF reported to me privately this bug is cured; the 8.6.0.0.b4 (beta release) for Windows from Activestate gave this effect. I can report 'fully cured and distributed' on this question with 8.6.0.0.b5. The resulting code runs faster too, not surprising as wish doesn't have to keep on finding blocks of memory. -------------- ** How to call one's own methods in TclOO ** 2010-12-02 [jbr] How to call ones own methods in TclOO? I don't do a lot of OO programming but I've tried snit and tcl oo on occasion. Today my question is, What best for calling a TclOO method from another method of the same object? 1. my some_method arg1 arg2 ... 2. [[self]] some_method arg1 arg2 ... 3. some_method arg1 arg2 Option #3 doesn't appear to work, I guess namespace command path nesting isn't working as I thought it might? ?? Thanks [gwm] Correct, option 3 deliberately does not work. 1 & 2 are equivalent although I would suggest using 1 so that any modification in a future release of TclOO affecting the 'my' operation would be implemented into your code. Method 3 is more like how C++ would be coded; use of 'my' ensures that any overridden method of the base class is called by methods in the base class which call the (overridden) method. -------------- ** How to http "GET" without using http package ? ** [Kirov] How to http "GET" without using http package ? fconfigure manual page says : "Upon output (i.e., with puts), the I/O system translates newlines to the external end-of-line representation." This doesn't work : ====== proc down {args} { # splitting first arg into usefull components set srv [lindex [split [lindex $args 0] /] 2] set tar [join [lrange [split [lindex $args 0] /] 3 end] /] # connecting socket set s [socket $srv 80] # requesting target url via http protocol puts $s "GET /$tar HTTP/1.0"; flush $s puts $s "Host: $srv\n\n"; flush $s # check if active socket while {[gets $s in] != -1} { # data handling puts $in } close $s } down http://www.tcl.tk/man/tcl8.5/TclCmd/fconfigure.htm ====== But this works just fine : ====== proc down {args} { # splitting first arg into usefull components set srv [lindex [split [lindex $args 0] /] 2] set tar [join [lrange [split [lindex $args 0] /] 3 end] /] # connecting socket set s [socket $srv 80] # requesting target url via http protocol puts $s "GET /$tar HTTP/1.0"; flush $s puts $s "Host: $srv"; flush $s puts $s ""; flush $s # check if active socket while {[gets $s in] != -1} { # data handling puts $in } close $s } down http://www.tcl.tk/man/tcl8.5/TclCmd/fconfigure.htm ====== My question is : Why ? 2011-11-20 [AMW] The two versions do NOT send identical requests! Version 1 sends '''two '''empty lines (three newlines) after the last HTTP header line ("Host:"...): two newlines generated by "\n\n", a third being added by the '''puts''' command when called without ''-nonewline''. Version 2 correctly sends just '''one''' empty line. Version 1 could be fixed in either of the following ways: ====== puts -nonewline $s "Host: $srv\n\n" puts $s "Host: $srv\n" ====== By the way: a single call to '''flush $s''' after sending the last byte would suffice, and will enhancen performance on connections with poor bandwith. ---- ** Too many initializer's errors in MS VS 2005; while writing a Tcl extension for C++)** [To Many Initiallizers error in MS VS 2005] Hello everyone, I am trying to write a Tcl extension for C++. Below is my code. int DLLEXPORT LitePoint_Init(Tcl_Interp *interp) { if (Tcl_InitStubs(interp,TCL_VERSION,0)==NULL) { return TCL_ERROR; } if (Tcl_PkgProvide(interp, "Hello", "1.0") == TCL_ERROR) { return TCL_ERROR; } Tcl_Command Tcl_CreateObjCommand(interp, "connect", ConnectSystem , NULL, NULL); return TCL_OK; } Below is the ConnectSystem proc. static int ConnectSystem(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[]) { int LP_InitTester(char *ipAddress); return TCL_OK; } ConnectSystem is calling another function LP_InitTester(). I am using MS VC++ 2005. When i try to build it, it's giving me " Too many initiallizers " pointing at Tcl_Command Tcl_CreateObjCommand(). How do i resolve this. Thanks Tcl_CreateObjCommand(interp, "connect", ConnectSystem , NULL, NULL); does not require the type of its return argument (Tcl_Command) to be declared too. Compiler gets that from the tcl.h file. just omit Tcl_Command from your code. --------------- ** Increasing the number of elements in a graph option ** [KESHAV] - 2010-08-19 00:37:40: HI, I am using a graph command from [BLT]/TK. The -xdata and -ydata options takes only 349524 elements. Is there any way to increase it? Or any settings to overcome this limitation? Please help [gold] 2010-10-11, found ref. http://www.usenix.org/events/tcl98/tcl98/full_papers/howlett/howlett_html/howlett.html ---- ** Problem with the thrashcan object for canvas on Canvas Object Movement ** [gold] 2Aug2010: I loaded a thrashcan object for canvas on Canvas Object Movement Example, [Canvas Object Movement Example]. This trashcan is sticking a little,eg sometimes the object does not disappear over the X on the first move or entry. Can somebody fix this item? Thanks. The deep patch appears to be: if { $y >= 20 && $y <= 70 } { if { $x >= 20 && $x <= 70 } {$w delete obj_$tilex } } #maybe should [lindex obj_$tilex 1 ]etc ? ---- ** Drawing a new series or new dataplot using Tklib Plotchart ** [JULY] - 2010-07-30 Question: Hi, I am using TKlib Plotchart. Once I have drawn a plot, say an xyplot, I want to clear it and draw a new series or new dataplot. I am unable to find any command to clear the plots and draw a new one. I tried using the destroy command, but it doesn't work. I don't want to destroy the whole canvas to plot all over again. Any suggestions/comments are appreciated! ---- [gold] Possible to 1)raise or lower the previous work on the canvas, 2)raise a covering object (white rectangle) or 3)write on top? I installed a raise or lower button in [Chinese Xianqi Chessboard]. grid is a tag on created objects in canvas. .cv itemconfigure grid -fill blue if { $state2 == 1 } { .cv raise grid ;} if { $state2 == 2 } { .cv lower grid ;} and [Simple Canvas Demo] Also, look at my [gold] perambulations with $c addtag point withtag $item & $w addtag selected withtag current on [Ask, and it shall be given # 7]. If you can add a tag to current and selected plot_1 like $w addtag plot_1 withtag current, you can raise or lower plot_1 with .c raise plot_1 or .c lower plot_1.(or .c lower all?) ---- ** Low volume level for a 24 bit wave file using snack ** Sergey, 10 july 2010 I have a problem with snack, which i can't find solution for. If i open a 24 bit wave file using snack and try to save it, resulting wave file has extremely low volume level, but if file is 16 or 32 bit, everything goes fine. Same thing happens in wavesurfer, so it's likely to be snack bug. Does anyone know about this bug? Is there any workaround? Thanks in advance. ---- ** Making a tk image from a tk widget ** [ARR] - 2010-06-30 Question 1: Hello specialists, how can I make a tk image from a tk widget? Answer 1: use the image command: '''image create photo widget_image -format window -data $widget''' Question 2: This is fine, but the widget must be fully visible. So, how can I make an image from a withdrawn widget? Any ideas anybody? Answer 2: ??? ---- ** Errors with tests for enable threads ** [rhinerfeld] - 2009-09-02 18:56:28 I have just downloaded the TK8.5.7 build. I am using Linux Fedora Core 10 as an OS. I configure for --enable-threads and then make test. I receive a number of errors from the tests that are run. Tests ended at Wed Sep 02 18:45:24 EDT 2009 all.tcl: Total 8788 Passed 7776 Skipped 945 Failed 67 Sourced 87 Test Files. Files with failing tests: canvText.test entry.test filebox.test font.test scrollbar.test spinbox.test text.test textDisp.test textImage.test textTag.test textWind.test unixEmbed.test unixFont.test unixSelect.test unixWm.test wm.test Number of tests skipped for each constraint: 12 altDisplay 1 aqua 16 colorsFree 3 colorsLeftover 21 defaultPseudocolor8 10 emptyTest 139 fonts 1 havePseudocolorVisual 6 knownBug 1 memory 103 nonPortable 33 nt 5 pseudocolor8 72 secureserver 11 testmetrics 7 testwinevent 141 textfonts 1 unthreaded 1 userInteraction 310 win 51 winSend Is this normal? ---- ** Errors in a Hello world code (attempting to make an IDE in C) ** [arin] - 2010-06-09 02:10:43 hi, i am working on an ubuntu system. My aim is to basically make an IDE in C language using GUI tools from TCL/TK. I installed tcl 8.4, tk8.4, tcl8.4-dev, tk8.4-dev and have the tk.h and tcl.h headers file in my system. But, when I am running a basic hello world program it's showing a hell lot of errors. #include "tk.h" #include "stdio.h" void hello() { puts("Hello C++/Tk!"); } int main(int, char *argv[]) { init(argv[0]); button(".b") -text("Say Hello") -command(hello); pack(".b") -padx(20) -pady(6); } Some of the errors are tkDecls.h:644: error: expected declaration specifiers before ‘EXTERN’ /usr/include/libio.h:488: error: expected ‘)’ before ‘*’ token In file included from tk.h:1559, from new1.c:1: tkDecls.h:1196: error: storage class specified for parameter ‘TkStubs’ tkDecls.h:1201: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token /usr/include/stdio.h:145: error: storage class specified for parameter ‘stdin’ tk.h:1273: error: declaration for parameter ‘Tk_PhotoHandle’ but no such parameter Can anyone please tell me how can I rectify these errors? Please help... [AM] A better place to ask such questions is comp.lang.tcl ---- ** Getting rid of a console window for a game listed at the bottom of Mahjong Style Deletion page 99 [gold] 5jun2010. I have some starter code for a game listed at the bottom of Mahjong Style Deletion page. when i drop the cheap_poker.tcl into etcl, i get a console window that i don't want. I have a statement for console hide but doesn't seem to work. How do i get rid of console window? thanks,[gold] [AMG]: [[[console] hide]] works just fine for me. I don't know what your problem could be. I'm not familiar with [eTcl]; maybe it's been customized somehow. By the way, do you realize your last edit deleted this page? Please be more careful in the future! [gold] Problem gone. I'll close out this question. Have rewritten code leaving out some upvar and canvas name substitutions. Problem gone. rewritten code left at [Mahjong_Style_Deletion] ---- ** Running "cd" , "source