• change background of tkk::button on Windows?

    From Ralf Fassel@21:1/5 to All on Tue May 28 12:52:24 2024
    tcl + tk 8.6.14
    Windows 10

    On *Windows*, how can I change the background of a ttk::button to some
    color?

    On Linux, this works:

    ttk::style configure TButton -background red
    pack [ttk::button .b -text Button]

    black text on red background.
    On Windows, however, there is only a tiny red ring around the button
    with the above code, and the button background itself is the usual grey.

    I tried also:

    ttk::style map TButton -background [list !disabled red]
    (same effect as above, red ring)

    I see
    ttk::style element options TButton.label
    -compound -space -text -font -foreground -underline -width -anchor -justify -wraplength -embossed -image -stipple -background

    But how do I get at the -background of the TButton.label?
    ttK::style 'configure' or 'map' on TButton.Label or TButton.label does
    not change anything in the ttk::button (though
    https://tkdocs.com/tutorial/styles.html
    somehow indicates it could ... maybe).

    TNX
    R' (ttk::styles look good, but they are driving me mad)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From greg@21:1/5 to All on Wed May 29 19:49:53 2024
    Am 28.05.24 um 12:52 schrieb Ralf Fassel:
    tcl + tk 8.6.14
    Windows 10

    On *Windows*, how can I change the background of a ttk::button to some
    color?

    On Linux, this works:

    ttk::style configure TButton -background red
    pack [ttk::button .b -text Button]

    black text on red background.
    On Windows, however, there is only a tiny red ring around the button
    with the above code, and the button background itself is the usual grey.

    I tried also:

    ttk::style map TButton -background [list !disabled red]
    (same effect as above, red ring)

    I see
    ttk::style element options TButton.label
    -compound -space -text -font -foreground -underline -width -anchor -justify -wraplength -embossed -image -stipple -background

    But how do I get at the -background of the TButton.label?
    ttK::style 'configure' or 'map' on TButton.Label or TButton.label does
    not change anything in the ttk::button (though
    https://tkdocs.com/tutorial/styles.html
    somehow indicates it could ... maybe).

    TNX
    R' (ttk::styles look good, but they are driving me mad)
    Hello,
    As far as I understand, the winnative, xpnative and vista themes are
    limited in what you can change.

    https://wiki.tcl-lang.org/page/Ttk#67395ef1c74680130d5bdb83dbfe0426dc5c1a6a3a7ecdf4f591c0476fe58df6

    One option is to use a different theme.
    ttk::style theme names
    ttk::style theme use clam


    mfg
    Gregor

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From greg@21:1/5 to All on Thu May 30 13:29:37 2024
    Am 28.05.24 um 12:52 schrieb Ralf Fassel:
    tcl + tk 8.6.14
    Windows 10

    On *Windows*, how can I change the background of a ttk::button to some
    color?

    On Linux, this works:

    ttk::style configure TButton -background red
    pack [ttk::button .b -text Button]

    black text on red background.
    On Windows, however, there is only a tiny red ring around the button
    with the above code, and the button background itself is the usual grey.

    I tried also:

    ttk::style map TButton -background [list !disabled red]
    (same effect as above, red ring)

    I see
    ttk::style element options TButton.label
    -compound -space -text -font -foreground -underline -width -anchor -justify -wraplength -embossed -image -stipple -background

    But how do I get at the -background of the TButton.label?
    ttK::style 'configure' or 'map' on TButton.Label or TButton.label does
    not change anything in the ttk::button (though
    https://tkdocs.com/tutorial/styles.html
    somehow indicates it could ... maybe).

    TNX
    R' (ttk::styles look good, but they are driving me mad)


    from the excellent https://tkdocs.com/tutorial/styles.html
    "You'll sometimes try to change an option that is supposed to exist
    according to element options, but it will have no effect..."

    a colored button, but without text:

    package require Tk

    set iw 76
    set ih 25
    set img1 [image create photo -width $iw -height $ih]
    $img1 put {#ff0000} -to 0 0 $iw $ih

    set img2 [image create photo -width $iw -height $ih]
    $img2 put {#00ff00} -to 0 0 $iw $ih

    set img3 [image create photo -width $iw -height $ih]
    $img3 put {#0000ff} -to 0 0 $iw $ih

    ttk::style configure Bone.TButton
    ttk::style element create Bone.image image [list $img1 pressed $img2
    active $img3] -border {2 4} -sticky we
    #ttk::style element create Bone.image image [list $img1 pressed $img2
    active $img3] -border {2 4} -sticky snwe
    ttk::style layout Bone.TButton [list Bone.image -sticky nswe]


    set b1 [ttk::button .b1 -text "Button1" -style Bone.TButton]
    set b2 [ttk::button .b2 -text "Button2"]

    # Packe die Buttons
    pack $b1 $b2

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From greg@21:1/5 to All on Thu May 30 13:46:48 2024
    Am 30.05.24 um 13:29 schrieb greg:
    Am 28.05.24 um 12:52 schrieb Ralf Fassel:
    tcl + tk 8.6.14
    Windows 10

    On *Windows*, how can I change the background of a ttk::button to some
    color?

    On Linux, this works:

       ttk::style configure TButton -background red
       pack [ttk::button .b -text Button]

    black text on red background.
    On Windows, however, there is only a tiny red ring around the button
    with the above code, and the button background itself is the usual grey.

    I tried also:

       ttk::style map TButton -background [list !disabled red]
       (same effect as above, red ring)

    I see
       ttk::style element options TButton.label
       -compound -space -text -font -foreground -underline -width -anchor
    -justify -wraplength -embossed -image -stipple -background

    But how do I get at the -background of the TButton.label?
    ttK::style 'configure' or 'map' on TButton.Label or TButton.label does
    not change anything in the ttk::button (though
       https://tkdocs.com/tutorial/styles.html
    somehow indicates it could ... maybe).

    TNX
    R' (ttk::styles look good, but they are driving me mad)


    from the excellent https://tkdocs.com/tutorial/styles.html
    "You'll sometimes try to change an option that is supposed to exist
    according to element options, but it will have no effect..."

    a colored button, but without text:

    package require Tk

    set iw 76
    set ih 25
    set img1 [image create photo -width $iw -height $ih]
    $img1 put {#ff0000} -to 0 0 $iw $ih

    set img2 [image create photo -width $iw -height $ih]
    $img2 put {#00ff00} -to 0 0 $iw $ih

    set img3 [image create photo -width $iw -height $ih]
    $img3 put {#0000ff} -to 0 0 $iw $ih

    ttk::style configure Bone.TButton
    ttk::style element create Bone.image image [list $img1  pressed $img2
    active $img3] -border {2 4} -sticky we
    #ttk::style element create Bone.image image [list $img1  pressed $img2 active $img3] -border {2 4} -sticky snwe
    ttk::style layout Bone.TButton [list Bone.image -sticky nswe]


    set b1 [ttk::button .b1 -text "Button1" -style Bone.TButton]
    set b2 [ttk::button .b2 -text "Button2"]

    # Packe die Buttons
    pack $b1 $b2
    with text

    package require Tk

    puts [ttk::style theme use]

    set iw 76
    set ih 25
    set img1 [image create photo -width $iw -height $ih]
    $img1 put {#ff0000} -to 0 0 $iw $ih

    set img2 [image create photo -width $iw -height $ih]
    $img2 put {#00ff00} -to 0 0 $iw $ih

    set img3 [image create photo -width $iw -height $ih]
    $img3 put {#0000ff} -to 0 0 $iw $ih

    ttk::style configure Bone.TButton
    ttk::style element create Bone.image image [list $img1 pressed $img2
    active $img3] -border {2 4} -sticky we
    #ttk::style element create Bone.image image [list $img1 pressed $img2
    active $img3] -border {2 4} -sticky snwe
    ttk::style layout Bone.TButton [list Bone.image -sticky nswe
    Button.text -sticky nswe]


    set b1 [ttk::button .b1 -text "Button1" -style Bone.TButton]
    set b2 [ttk::button .b2 -text "Button2"]

    # Packe die Buttons
    pack $b1 $b2
    puts [ttk::style layout Bone.TButton ]
    puts [ttk::style layout TButton ]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ralf Fassel@21:1/5 to All on Thu May 30 14:59:30 2024
    * greg <[email protected]>
    | Am 28.05.24 um 12:52 schrieb Ralf Fassel:
    | > tcl + tk 8.6.14
    | > Windows 10
    | > On *Windows*, how can I change the background of a ttk::button to
    | > some color?
    --<snip-snip>--
    | Hello,
    | As far as I understand, the winnative, xpnative and vista themes are
    | limited in what you can change.

    | https://wiki.tcl-lang.org/page/Ttk#67395ef1c74680130d5bdb83dbfe0426dc5c1a6a3a7ecdf4f591c0476fe58df6

    Thanks greg, seems I'm not the only one going mad (but cleary this is Microsofts fault this time :-) The documentation on Windows themes
    seems limited to the MSDN manpages for the function calls.

    | One option is to use a different theme.
    | ttk::style theme names
    | ttk::style theme use clam

    Not an option here, L&F needs to be close to "modern" Windows native.
    Eg using clam, many backgrounds are a darker grey than the rest of the
    UI, so I get a checkerboard of light and dark backgrounds :-/

    I fell back to using a regular Tk button with [-relief ridge] and the
    font from the ttk-button, which is not optimal, but "close enough".

    R'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)