Sujet : Re: Images on disabled buttons look bad
De : saitology9 (at) *nospam* gmail.com (saito)
Groupes : comp.lang.tclDate : 28. Feb 2025, 19:09:05
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vpsu42$3osva$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla Thunderbird
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