Boton Spinbox

I haven't been on it very long, but ever since I had a stroke and had to relearn almost everything from walking to TCL, I'm here more and more now. Today I would like to Collaborate with a Button that when clicked changes its content or one of its configurable functions. It would be like a rotary button. I don't know if there is already something similar.

I was inspired by the SpinBox, but I did it with a value that changes in a list. If the text is "JPEG BMP GIF TIF" and we start the Button with "JPEG", we look up the list for the current value and update it with the next value in the list.

For the next stroke, I think I will ask to be taught English and not Spanish which is my native language.

proc tmsg {{txt ""} {ty "ok"} {img "info"}} {
return [tk_messageBox -message $txt -type $ty -icon $img]
}

proc ciclo {{lista ""} {var ""} {ps 1}} {
#tmsg $lista\n$var\n
set len [llength $lista]
if {[lsearch $lista $var]>=0} {set pos [lsearch $lista $var]}
incr pos
if {$pos>=$len} {set nv [lindex $lista 0]} else {set nv [lindex $lista $pos]}
return $nv
}


catch {destroy .t}
toplevel .t
place [button .t.c -text "JPEG" -bg yellow -command {
.t.c config -bg [ciclo "red green cyan yellow" [.t.c cget -bg]] -text [ciclo "JPEG GIF BMP SVG" [.t.c cget -text]]
}] -x 0 -y 0
wm withdraw .

Jeff Smith 2023-05-16: Below is an online demo using CloudTk. This demo runs "Boton Spinbox" in an Alpine Linux Docker Container. It is a 27.4MB image which is made up of Alpine Linux + tclkit + Boton-Spinbox.kit + libx11 + libxft + fontconfig + ttf-linux-libertine. It is run under a user account in the Container. The Container is restrictive with permissions for "Other" removed for "execute" and "read" for certain directories.



arjen - 2023-05-16 14:18:18

The demo by Jeff has some quirk: the colour is not updated immediately. I am not sure it is a matter of delay or whether it requires mouse movement. Well, that is a different issue than the questions in the text :).