I've been getting into ltk, since I wanted to do some GUI programming again. I'm currently trying some things, one of them being changing the color of a button. This should be possible becaus of this bit of documentation http://www.peter-herth.de/ltk/ltkdoc/node18.html. But it is not really specified how I could do it. I've tried with 'configure' and I tried in the initialization code and even in the 'pack' function, but it does not seem to work. It might be nice if the documentation told me how to do this.
The working code looks like this. How do I change the color of the button?
``` (with-ltk () (let* ((frame (make-instance 'frame)) (button (make-instance 'button :master frame :text "Hello, World" :command (lambda () (print "Hello, World"))))) (pack frame) (pack button))) ```
Thanks in advance for any help.
Greetings, Tom
On Fri, Jul 26, 2019 at 08:58:20PM +0200, Tom Hassel wrote:
Hello!
I've been getting into ltk, since I wanted to do some GUI programming again.
Very good! :)
[...]
The working code looks like this. How do I change the color of the button?
Long story short: ltk uses, by default, a set of widget (called "ttk") that does not support many configuration option that the old ones supported instead.
But this is only part of the story actually, I think this link on stack overflow (see the accepted reply) also could help you:
https://stackoverflow.com/questions/53504488/ltk-button-height-not-configura...
and the link below (also contained in the aforementioned page) probably is going to solve your issue:
https://mailman.common-lisp.net/pipermail/ltk-user/2016-June/000625.html
to try to clarify a bit more i suggest you take a look at:
https://www.tcl.tk/man/tcl8.6/TkCmd/button.htm
as you can see when the old widgets (i.e. non ttk) are used you get a command option: "background". The value can be set via the function "configure" as shown in:
http://www.peter-herth.de/ltk/ltkdoc/node13.html
by comparison see the new, (ttk) widget:
https://www.tcl.tk/man/tcl8.6/TkCmd/contents.htm
it does have the same option anymore, it use a theme system to drive the widgets visuals.
To change a background button of a ttk you should probably write a theme but for lack of skills, i can not help much about that, sorry! ^^;
Tangentially i suggest you to stick with the ttk widget set as it help to achieve a consistent visual appearance that improve usability, but this is matter of personal opinion i guess.
Hope this help!
Bye! C.
On Fri, 26 Jul 2019 20:58:20 +0200, Tom Hassel trashtalk217@gmail.com wrote:
I've been getting into ltk, since I wanted to do some GUI programming again. I'm currently trying some things, one of them being changing the color of a button. This should be possible becaus of this bit of documentation http://www.peter-herth.de/ltk/ltkdoc/node18.html. But it is not really specified how I could do it. I've tried with 'configure' and I tried in the initialization code and even in the 'pack' function, but it does not seem to work. It might be nice if the documentation told me how to do this.
The working code looks like this. How do I change the color of the button?
LTK will use the ttk widgets whenever possible, so you have a ttk::button which, as you can see from the tkdocs (http://tcl.tk/man/tcl8.6/TkCmd/ttk_button.htm) does not have a background option.
Instead you will have to create a style for your button that has a black background. A first pass might look something like this (I used format-wish because I could not find any builtin LTK commands for manipulating styles):
(with-ltk () (let* ((frame (make-instance 'frame)) (button (make-instance 'button :master frame :text "Hello, World" :command (lambda () (print "Hello, World"))))) (format-wish "ttk::style configure black.TButton -background black") (configure button :style "black.TButton") (pack frame) (pack button)))
NB: Styles in Tk are in a global namespace with inheritence based upon names, so "black.TButton" inherits all attributes of "TButton" (the default style for a button) which in turn inherits from the root style "."
You may notice that the above code causes the button to go back to its default color if you hover over it. This is because we only changed the *defualt* background color, not any of the dynamic background colors. If you disable the button, it will similarly return to its default color. Dynamic attributes are set with "ttk::style map" and are stored in Tk's equivalent of a plist. To set all dynamic colors also to black the following should work:
(with-ltk () (let* ((frame (make-instance 'frame)) (button (make-instance 'button :master frame :text "Hello, World" :command (lambda () (print "Hello, World"))))) (format-wish "ttk::style configure black.TButton -background black") (format-wish "ttk::style map black.TButton -background [list active black disabled black readonly black]") (configure button :style "black.TButton") (pack frame) (pack button)))
If you only want to override some of the dynamic background values, you can use a shorter list.
There's sufficient introspection and documentation in Tk to discover all possible values on your own, but a good cheatsheet is can be found at https://wiki.tcl-lang.org/page/Changing+Widget+Colors
HTH, Jason
Hi
I'm sorry for the radio silence. Because of vacation related reasons I had no keyboard in front of me for a while nor a good internet connection. Thanks for the resources and the feedback. It's reassuring to know that such a relatively out there library for an out there language still has people who are willing to lend their expertise to an amateur (me in this case).
Greetings, Tom
Op wo 31 jul. 2019 om 17:34 schreef cage cage-dev@twistfold.it:
On Tue, Jul 30, 2019 at 11:55:30PM +0000, Jason Miller wrote:
Hi!
[...]
Instead you will have to create a style for your button that has a black background.
[...]
These are useful informations, thank you! C.
On Fri, Aug 09, 2019 at 09:29:42AM +0200, Tom Hassel wrote:
Hi
Hello!
I'm sorry for the radio silence. Because of vacation related reasons I had no keyboard in front of me for a while nor a good internet connection.
I hope you are enjoying your vacation! :) Let us know about your progress with LTK and feel free to ask if you got problems! :)
Bye! C.