• How do I get the selection of a BWidget ComboBox?

    From Luc@luc@sep.invalid to comp.lang.tcl on Thu Mar 7 00:44:12 2024
    From Newsgroup: comp.lang.tcl

    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
    --
    Luc



    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From nemethi@csaba.nemethi@t-online.de to comp.lang.tcl on Thu Mar 7 16:33:13 2024
    From Newsgroup: comp.lang.tcl

    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:csaba.nemethi@t-online.de

    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Luc@luc@sep.invalid to comp.lang.tcl on Fri Mar 8 17:18:41 2024
    From Newsgroup: comp.lang.tcl

    On Thu, 7 Mar 2024 16:33:13 +0100, nemethi wrote:

    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] }
    **************************

    That works. Thanks.

    Would you by any chance know how to control the background color of
    a ttk::spinbox? Mine looks gray and strange.

    I tried setting it to #FFFFFF but that changes the color of the arrows' background, not the value input box as I expected.
    --
    Luc


    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From nemethi@csaba.nemethi@t-online.de to comp.lang.tcl on Fri Mar 8 22:31:41 2024
    From Newsgroup: comp.lang.tcl

    Am 08.03.24 um 21:18 schrieb Luc:
    On Thu, 7 Mar 2024 16:33:13 +0100, nemethi wrote:

    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] }
    **************************

    That works. Thanks.

    Would you by any chance know how to control the background color of
    a ttk::spinbox? Mine looks gray and strange.

    I tried setting it to #FFFFFF but that changes the color of the arrows' background, not the value input box as I expected.


    ttk::style map TSpinbox -fieldbackground {readonly white}
    --
    Csaba Nemethi https://www.nemethi.de mailto:csaba.nemethi@t-online.de

    --- Synchronet 3.20a-Linux NewsLink 1.114