tk button background color, dynamically change

1,210 views
Skip to first unread message

Ben Arthur

unread,
Aug 28, 2014, 10:48:06 AM8/28/14
to julia...@googlegroups.com
i'm new to Tk and am having trouble dynamically setting the background color of a button.  all i get is:

julia> configure(myButton, background="red")

ERROR: TclError("unknown option \"-background\"")

ditto for "bg", etc.


more generally, is there a way to get a list of all available options?  would be useful self-documentation...

thanks.

j verzani

unread,
Aug 28, 2014, 1:26:16 PM8/28/14
to julia...@googlegroups.com
With the newish Tk widgets, you need to configure the style of the button, not the individual button:

using Tk
w = Toplevel()
tcl("ttk::style", "configure", "TButton", foreground="red", font="helvetica 24")
b = Button(w, "test")
pack(b)

As for available options, the Tk documentation is the best bet (https://www.tcl.tk/man/tcl/TkCmd/contents.htm).

Milan Bouchet-Valat

unread,
Aug 28, 2014, 5:23:46 PM8/28/14
to julia...@googlegroups.com
Le jeudi 28 août 2014 à 10:26 -0700, j verzani a écrit :
> With the newish Tk widgets, you need to configure the style of the
> button, not the individual button:
>
>
> using Tk
> w = Toplevel()
> tcl("ttk::style", "configure", "TButton", foreground="red",
> font="helvetica 24")
> b = Button(w, "test")
> pack(b)
>
>
> As for available options, the Tk documentation is the best bet
> (https://www.tcl.tk/man/tcl/TkCmd/contents.htm).
Another option to seriously consider is to use a more modern toolkit
like GTK or Qt, and create most of the GUI using a GUI creator (Glade,
QtCreator). Speaking as the unfortunate maintainer of a R package based
on Tcl/Tl -- do not reproduce mistakes of the past. ;-)


My two cents
Reply all
Reply to author
Forward
0 new messages