1

Beginner question: I'm trying to change the colour of my GUI, particularly the radiobuttons. I need inverted colours, so black background, white text.

self.radiobuttonVariable = Tkinter.IntVar()
radiobutton1 = Tkinter.Radiobutton(self, text=u'E', variable = self.radiobuttonVariable, 
                                       bg='black', fg='white' activebackground='black', activeforeground='white', 
                                       value = 1, command = self.RadioSelect)
radiobutton1.grid(column=2, row=1, sticky='ES')

This looks just fine, but when I press the button, it's the dot is there only as long I'm pressing it, disappears as soon as I let it go. The variable doesn't change, it stays on the right value, just that the dot disappears. No issue whatsoever when I remove the colour-management options. Any ideas?

zephi
  • 418
  • 3
  • 16

1 Answers1

3

As far as I can tell, specifying the foreground (presumably for the text) also sets the selected "dot color". You can set the selectcolor attribute of the element to color the "background" of the radiobutton so that you can see the white dot.

For example, selectcolor='red' in Windows:

win-red

Be aware that the manpage indicates that coloring all radio buttons with selectcolor (instead of only the selected button) may be Windows-only:

Under Windows, this color is used as the background for the indicator regardless of the select state.

That being said, I got the same effect in linux under Python 2.7 and 3.3:

linux-red

I just used red to distinguish the part of the widget that selectcolor affected, you'd probably want selectcolor='black' or something a bit lighter to show the depression selectcolor='#222222' (below):

win-dark

jedwards
  • 29,432
  • 3
  • 65
  • 92
  • Thanks, that indeed works. Now that I think of it, I should've just studied the documentation. Is there a way to alter default colour values for all widgets of particular type, so that I don't have to add options to every widget in my GUI? – zephi Mar 19 '15 at 11:08
  • 1
    @zephi If you keep track of your widgets somehow (append their references to in a list maybe), you can iterate through them and set attributes that they have in common (e.g. `fg`, `bg`), but things like `selectcolor` will need to be set in the respective widgets, since not all widgets have that attribute. – jedwards Mar 19 '15 at 11:11
  • That's a neat idea for more complex user interfaces, might just create one list per widget type to eliminate unknown option error. Thanks a lot! – zephi Mar 19 '15 at 11:21