Am 07.03.24 um 04:44 schrieb Luc:
I have a BWidget ComboBox with a lot of items.
set SomeVar "hello"
set combotext "Take your pick"
$::c1.outerframe.frame4.combo configure -text "Take your pick"
I select one item from the ComboBox:
$::c1.outerframe.frame4.combo configure -modifycmd "puts [$::c1.outerframe.frame4.combo get]"
Take your pick
It doesn't matter which item I pick:
Take your pick
Take your pick
Take your pick
Add a new line:
$::c1.outerframe.frame4.combo configure -textvariable SomeVar
I select one item from the ComboBox:
$::c1.outerframe.frame4.combo configure -modifycmd "puts $SomeVar"
hello
It doesn't matter which item I pick:
hello
hello
hello
The manual also says,
"pathName getvalue
Returns the index of the current text of the ComboBox in the list of
values, or -1 if it doesn't match any value."
Well, I cannot choose anything that is not in my values list, but no
matter what I choose, pathName getvalue returns -1.
How do I capture the current selection of a BWidget ComboBox?
The only page I could find with that specific question has been
unanswered for 10 years.
https://stackoverflow.com/questions/17424489/tcl-bwidget-how-can-i-pass-my-combobox-selected-value-to-the-command
I see several problems here:
1. The line
$::c1.outerframe.frame4.combo configure -modifycmd "puts [$::c1.outerframe.frame4.combo get]"
sets the -modifycmd option of the combobox to "puts Take your pick",
which will throw an error message rather than printing "Take your pick".
Are you sure you have this same line in your script?
2. To get rid of the error message, you could change the above line to
become
$::c1.outerframe.frame4.combo configure -modifycmd [list puts [$::c1.outerframe.frame4.combo get]]
which would produce the output "Take your pick" whenever an item is
selected, as stated in your posting. This is, however, not the expected behavior.
3. To solve the problem, you should change the above line to become
$::c1.outerframe.frame4.combo configure -modifycmd { puts [$::c1.outerframe.frame4.combo get] }
which will work as expected, due to the use of braces instead of
quotation marks. Even better (the recommended way):
$::c1.outerframe.frame4.combo configure -modifycmd [list modifCmd $::c1.outerframe.frame4.combo]
proc modifCmd w { puts [$w get] }
4. The ComboBox getvalue command works for me as expected (it returns 0,
1, ... rather than -1). You have probably made a similar mistake as in connection with the -modifycmd option.
--
Csaba Nemethi
https://www.nemethi.de mailto:
[email protected]
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)