aj@bookac.com wrote:
> Once again, I appreciate the expeditiousness and comprehensiveness of
> your last post. That being said, the complaint comes when I load the
> script, NOT when I click on the button.
>
> Here is a complete script exemplifying the problem. Run this in your
> favorite wish interpreter to see if you get the same error I do.
> Hopefully uou have Iwidgets.
>
> I reduced the usage of the "rng" variable to one place, and wrapped it
> in quotes as you said to expand it.
>
> package require Iwidgets
>
> set f [frame .main]
>
> iwidgets::menubar $f.menu -menubuttons {
> menubutton range -text "VALUE" -menu {
> foreach rng {1} {
> radiobutton range -label "$rng" -command {puts hello}
> }
> }
> }
>
Ok, I didn't realize you were using Iwidgets. I haven't used iwidgets in
years and it appears to have some odd features. For example, I had no
idea you could have a "foreach" statement inside a "-menu" definition.
Are you certain you are allowed to do that? The only documentation I can
find doesn't say that's something you can do. It may be that the error
you are seeing is just a symptom of a bigger problem.
According to the documentation, the value for -menubuttons is a string
(*not* arbitrary code) and that the value is processed by subst. From
the menubar man page:
"The -menubuttons option as well as the -menu option is evaluated by
menubar with the subst command."
If that is true, what is probably happening is that your foreach code
isn't being run at all. I think what is happening is roughly the
equivalent of this:
subst {
foreach rng {1} {
radiobutton range -label "$rng" -command {puts hello}
}
}
Thus, subst tries to dereference $rng and fails.
Your best best is probably to do the foreach before creating the
menubar, creating a variable that contains the radiobutton definitions.
Then, use that variable as the value for -menu.
Something like this (totally untested, and just an educated guess):
foreach range {1 2 3 4 5 6 7 8 9 0} {
append buttons "[list radiobutton range$range -label $range \
-command [list doSomething $range]\n"
}
iwidgets::menubar $f.menu -menubuttons {
menubutton range -text "VALUE" -menu $buttons
Although I'm sure you're trying to use iwidgets to make your job easier,
it looks like in this case it's making it much harder. Perhaps you
should consider just creating a menubar using standard tk commands.
Sorry I can't be of more help. Perhaps an iwidgets expert will weigh in
here.
--
Bryan Oakley
http://www.tclscripting.com
Received on Sun Apr 30 03:30:50 2006