[Tutor] Tkinter checkbutton

Alan Gauld alan.gauld at yahoo.co.uk
Thu Feb 24 05:25:26 EST 2022


On 24/02/2022 03:41, Phil wrote:
> Out of curiosity, I'm wondering if the select area (the area where the 
> tick is displayed when the button is selected) can be set when the 
> checkbutton is selected? 

Yes, you can supply a command function which is called whenever the
button is selected or deselected:

cb = tk.Checkbutton(top)
cb.pack()

def f():
	if cb['selectcolor'] != 'red':
		cb['selectcolor'] = 'red'
	else: cb['selectcolor'] = 'white'

	
>>> cb['command'] = f


> According to the documentation the default 
> colour is red but in my case it's white and doesn't change colour when 
> the checkbutton is selected.

It doesn't seem to change colour. It's just the colour of
the part of the widget that you select.

> This is from the tk docs. "selectcolor The color of the checkbutton when 
> it is set. By default, it is red."

I think the wording is misleading. I think it means
when the colour is set by the programmer not by the user.
But the default is definitely white, on Linux at least.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list