Adding borders to ttk radiobuttons

Terry Reedy tjreedy at udel.edu
Wed Mar 30 12:35:39 EDT 2016


On 3/30/2016 11:01 AM, Mark Lawrence via Python-list wrote:
> On 30/03/2016 15:45, ast wrote:
>>
>> "Mark Lawrence" <breamoreboy at yahoo.co.uk> a écrit dans le message de
>> news:mailman.204.1459343690.28225.python-list at python.org...
>>> I believe something like this should suffice to display borders around
>>> the radiobuttons.
>>>
>>> import tkinter as tk
>>> import tkinter.ttk as ttk
>>> root = tk.Tk()
>>> style = ttk.Style()
>>> style.configure('BW.TRadiobutton', borderwidth=5)
>>> buttonVar = tk.IntVar()
>>> rb1 = ttk.Radiobutton(text='Hello mum', variable=buttonVar, value=1)
>>> rb1.configure(style='BW.TRadiobutton')
>>> rb1.grid(row=0, column=0)
>>> rb2 = ttk.Radiobutton(text='Hello dad', variable=buttonVar, value=2)
>>> rb2.configure(style='BW.TRadiobutton')
>>> rb2.grid(row=1, column=0)
>>> root.mainloop()
>>>
>>> Sadly no borders :(  What have I missed?  Python 3.5.1 on Windows 10.
>>>
>>
>> it seems there is no border on the radio button
>>
>>> style.layout('BW.TRadiobutton')
>>
>> [('Radiobutton.padding', {'children': [('Radiobutton.indicator',
>> {'side': 'left', 'sticky': ''}), ('Radiobutton.focus', {'side': 'left',
>> 'sticky': '', 'children': [('Radiobutton.label', {'sticky':
>> 'nswe'})]})], 'sticky': 'nswe'})]
>
> That's as may be, but from Table 56 "ttk Radiobutton options not in
> ttk.Radiobutton" here
> http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-Radiobutton.html
> it says "borderwidth or bd - Configure this option using a style."

Components depend on the theme.  In some themes, Radiobutton does have a 
border.  On Windows 10, I ran

 >>> for s in style.theme_names():
	style.theme_use(s)
	style.theme_use()
	style.layout('TRadiobutton')

Theme names are ('winnative', 'clam', 'alt', 'default', 'classic', 
'vista', 'xpnative') with 'vista'the default. Outputs were the same as above

'vista'
[('Radiobutton.padding', {'sticky': 'nswe', 'children':
[('Radiobutton.indicator', {'sticky': '', 'side': 'left'}),
  ('Radiobutton.focus', {'sticky': '', 'children':
[('Radiobutton.label', {'sticky': 'nswe'})], 'side': 'left'})]})]

except for this

'classic'
[('Radiobutton.highlight', {'sticky': 'nswe', 'children': 
[('Radiobutton.border', {'sticky': 'nswe', 'children': 
[('Radiobutton.padding', {'sticky': 'nswe', 'children': 
[('Radiobutton.indicator', {'sticky': '', 'side': 'left'}), 
('Radiobutton.label', {'sticky': 'nswe', 'side': 'left'})]})]})]})]

.theme_names() only displays the themes for the OS.  I believe that 
there is a way to access themes for other OSes (unix, mac) but don't 
remember.

-- 
Terry Jan Reedy





More information about the Python-list mailing list