From: Luc <[email protected]>
Date: Wed Nov 16 14:42:56 GMT 2022
Subject: I can't parray in a text widget
Hi Luc,
no, you cannot 'parray into a text widget':
'parray' writes to stdout and a text widget wants
'$t insert <index where> <text>'.
I think the simplest solution is:
- look into the file 'parray.tcl' (on my installation it is located in
<path to my installation>/lib/tcl8.6
- rename the parray function, add another parameter to it
and replace the line 'puts stdout ...' with '$t insert ...'
HTH
Helmut
Thank you for the clarifications.
I am doing
foreach i [array names ::file_$argNumber] {
.t insert end "[set ::file_[set argNumber]($i)]\n"
}
A little ugly and hard to read, but it works.
I am really struggling with this:
--------------------
package require Tk
text .t -width 40 -height 6 -font "FreeSans 18"
pack .t
array set file_1 {name file1 date today size 100k}
array set file_2 {name file2 date today size 200k}
array set file_3 {name file3 date today size 300k}
proc p.printfiles argNumber {
.t delete 1.0 end
.t insert end ::file_$argNumber
.t insert end "\n"
.t insert end "parray: [parray ::file_$argNumber]"
.t insert end "[set ::file_[set argNumber](size)]"
parray ::file_$argNumber
}
p.printfiles 2
--------------------
Result:
::file_2
argNumber
parray:
200k
I've tried all kinds of formats and escaping and can't get the code to
insert the output of [parray] into the text widget.
And the plot thickens. If I include [info vars] in those insert lines, the only var it finds is argNumber. What about the global vars? Where are they?
Maybe that is why it can't print [parray]?
No, that is not the reason because
1) the parray line at the end works fine in stdout.
2) this line works as expected:
.t insert end "[set ::file_[set argNumber](size)]"
What am I doing wrong?
proc p.printfiles argNumber {
.t delete 1.0 end
.t insert end ::file_$argNumber
.t insert end "\n"
.t insert end "parray: [parray ::file_$argNumber]"
.t insert end "[set ::file_[set argNumber](size)]"
parray ::file_$argNumber
}
And the plot thickens. If I include [info vars] in those insert
lines, the only var it finds is argNumber. What about the global
vars? Where are they?
Am 16.11.22 um 16:54 schrieb Luc:
Thank you for the clarifications.
I am doing
foreach i [array names ::file_$argNumber] {
.t insert end "[set ::file_[set argNumber]($i)]\n"
}
A little ugly and hard to read, but it works.
In order to iterate over an array, you can also use array get:
foreach {key val} [array get yourarray] {
puts "$key = $val"
}
which should be more readable.
Christian
- look into the file 'parray.tcl' (on my installation it is located in
<path to my installation>/lib/tcl8.6
Hi Luc,
no, you cannot 'parray into a text widget':
'parray' writes to stdout and a text widget wants
'$t insert <index where> <text>'.
I think the simplest solution is:
- look into the file 'parray.tcl' (on my installation it is located in
<path to my installation>/lib/tcl8.6
- rename the parray function, add another parameter to it
and replace the line 'puts stdout ...' with '$t insert ...'
HTH
Helmut
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 714 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 141:40:58 |
| Calls: | 12,088 |
| Calls today: | 1 |
| Files: | 14,998 |
| Messages: | 6,517,448 |