• Images on disabled buttons look bad

    From Martin (m0h)@user2544@newsgrouper.org.invalid to comp.lang.tcl on Wed Feb 26 22:49:24 2025
    From Newsgroup: comp.lang.tcl


    My image looks fine when it is on a normal button. When I change the state of the button to disabled the image is stippled. Is there a way to change this default behaviour?
    --- Synchronet 3.20c-Linux NewsLink 1.2
  • From Christian Gollwitzer@auriocus@gmx.de to comp.lang.tcl on Thu Feb 27 08:11:39 2025
    From Newsgroup: comp.lang.tcl

    Am 26.02.25 um 23:49 schrieb Martin (m0h):

    My image looks fine when it is on a normal button. When I change the state of the button to disabled the image is stippled. Is there a way to change this default behaviour?

    This is intended in order to provide visual feedback. If you use a ttk::button, you can provide your own disabled image instead. Create a disabled image e.g. grayscale or toned-down version, and then pass a
    list to -image. YOu can specify multiple images for different states of
    the button, so that should be
    "normalimage disabled disabledimage" (untested)

    See: https://www.tcl-lang.org/man/tcl/TkCmd/ttk_widget.htm#M-image

    Christian
    --- Synchronet 3.20c-Linux NewsLink 1.2
  • From Harald Oehlmann@wortkarg3@yahoo.com to comp.lang.tcl on Thu Feb 27 08:55:18 2025
    From Newsgroup: comp.lang.tcl

    Am 27.02.2025 um 08:11 schrieb Christian Gollwitzer:
    Am 26.02.25 um 23:49 schrieb Martin (m0h):

    My image looks fine when it is on a normal button. When I change the
    state of the button to disabled the image is stippled. Is there a way
    to change this default behaviour?

    This is intended in order to provide visual feedback. If you use a ttk::button, you can provide your own disabled image instead. Create a disabled image e.g. grayscale or toned-down version, and then pass a
    list to -image. YOu can specify multiple images for different states of
    the button, so that should be
    "normalimage disabled disabledimage" (untested)

    See: https://www.tcl-lang.org/man/tcl/TkCmd/ttk_widget.htm#M-image

    Christian

    Wow, I did not know this trick, awesome !

    Here is an example with the disabled state on tk 8.6:

    % ttk::button .b -image {::tk::icons::information disabled
    ::tk::icons::error}
    % pack .b
    shows the information icon
    % .b state disabled
    shows the error icon

    GREAT !!!

    Thanks Christian,
    Harald
    --- Synchronet 3.20c-Linux NewsLink 1.2
  • From Martin (m0h)@user2544@newsgrouper.org.invalid to comp.lang.tcl on Fri Feb 28 15:13:33 2025
    From Newsgroup: comp.lang.tcl


    Christian Gollwitzer <auriocus@gmx.de> posted:

    Am 26.02.25 um 23:49 schrieb Martin (m0h):

    My image looks fine when it is on a normal button. When I change the state of the button to disabled the image is stippled. Is there a way to change this default behaviour?

    This is intended in order to provide visual feedback. If you use a ttk::button, you can provide your own disabled image instead. Create a disabled image e.g. grayscale or toned-down version, and then pass a
    list to -image. YOu can specify multiple images for different states of
    the button, so that should be
    "normalimage disabled disabledimage" (untested)

    See: https://www.tcl-lang.org/man/tcl/TkCmd/ttk_widget.htm#M-image

    Christian
    Hello Christian,

    Thank you for the answer. I didn't know Ttk had this feature. Maybe I was a little too fixated on the documentation of the non-Ttk button.
    It is definetly good to know this feature exists, although I will have to see if it is worth the effort to implement this into my application as I rely on Tk buttons currently.

    Martin (m0h)
    --- Synchronet 3.20c-Linux NewsLink 1.2
  • From Martin (m0h)@user2544@newsgrouper.org.invalid to comp.lang.tcl on Fri Feb 28 15:14:54 2025
    From Newsgroup: comp.lang.tcl


    Harald Oehlmann <wortkarg3@yahoo.com> posted:

    Am 27.02.2025 um 08:11 schrieb Christian Gollwitzer:
    Am 26.02.25 um 23:49 schrieb Martin (m0h):

    My image looks fine when it is on a normal button. When I change the
    state of the button to disabled the image is stippled. Is there a way
    to change this default behaviour?

    This is intended in order to provide visual feedback. If you use a ttk::button, you can provide your own disabled image instead. Create a disabled image e.g. grayscale or toned-down version, and then pass a
    list to -image. YOu can specify multiple images for different states of the button, so that should be
    "normalimage disabled disabledimage" (untested)

    See: https://www.tcl-lang.org/man/tcl/TkCmd/ttk_widget.htm#M-image

    Christian

    Wow, I did not know this trick, awesome !

    Here is an example with the disabled state on tk 8.6:

    % ttk::button .b -image {::tk::icons::information disabled ::tk::icons::error}
    % pack .b
    shows the information icon
    % .b state disabled
    shows the error icon

    GREAT !!!

    Thanks Christian,
    Harald
    Hello Harald,

    thank you for the example. It was of great help to quickly test the Ttk feature in question.

    Martin (m0h)
    --- Synchronet 3.20c-Linux NewsLink 1.2
  • From saito@saitology9@gmail.com to comp.lang.tcl on Fri Feb 28 13:09:05 2025
    From Newsgroup: comp.lang.tcl

    On 2/28/2025 10:13 AM, Martin (m0h) wrote:

    It is definetly good to know this feature exists, although I will have to see if it is worth the effort to implement this into my application as I rely on Tk buttons currently.


    I think you could still achieve the effect you want with a little extra effort. Essentially you create a clone of your current button as a
    label, with the same image and text (perhaps, the text in a "inactive" font/color). Then whenever you change the state to inactive/disabled,
    you unpack the original button and pack this clone instead, and do the
    reverse when you restore the state.


    It just occurred to me while writing this that you could simply use a
    label instead of a button! A label doesn't normally respond to clicks
    and events so it is easier to work with in this case. You just add
    bindings for clicks and track its state and you are done.

    Here is a quick implementation:

    package req Tk

    label .l -text Hello -compound left -image [image create photo -file ..]
    bind .l <Button-1> respond_to_clicks
    pack .l

    proc respond_to_clicks {} {
    global my_state

    if {$my_state} {
    puts [clock seconds]
    }
    }

    # make it active
    # now the button reacts to mouse clicks
    set my_state 1

    # make it inactive
    set my_state 0




    --- Synchronet 3.20c-Linux NewsLink 1.2