bind $::widget <Key-1> {set ::widget::choice $i; puts $::widget::choice}
bind $::widget <Key-2> {set ::widget::choice $i; puts $::widget::choice}
bind $::widget <Key-3> {set ::widget::choice $i; puts $::widget::choice}
bind $::widget <Key-4> {set ::widget::choice $i; puts $::widget::choice}
This works fine.
I press 1, the app outputs 1. I press 2, the app outputs 2.
And so on.
However,
foreach i {1 2 3 4 5 6 7 8 9 0} {
bind $::widget <Key-$i> {set ::widget::choice $i; puts $::widget::choice}
}
I press 1, the app outputs 0. I press 2, the app outputs 0.
I press 3, the app outputs 0.
And so on.
The output always is the last item in the list. I tested that.
What in the blue blazes? I am completely stumped.
TIA
Check the available %-replacements for bind (most likely %K)when the bind is set:
use 'list' to set up the binding if the variables should get resolved
for anything more substantial than a 'puts', use a helper proc tocall when the event happens:
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 493 |
Nodes: | 16 (2 / 14) |
Uptime: | 31:31:46 |
Calls: | 9,740 |
Files: | 13,741 |
Messages: | 6,183,148 |