wx.ToggleButton background color foolishness

655 views
Skip to first unread message

Chris Spencer

unread,
Nov 27, 2010, 2:15:14 PM11/27/10
to wxpytho...@googlegroups.com
In the wxPython Demo, if you change this...
for word in "These are toggle buttons".split():
b = wx.ToggleButton(panel, -1, word)
self.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggle, b)
buttons.Add(b, flag=wx.ALL, border=5)

to this...

for word in "These are toggle buttons".split():
b = wx.ToggleButton(panel, -1, word)
b.SetBackgroundColour(wx.Colour(255,0,0))
self.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggle, b)
buttons.Add(b, flag=wx.ALL, border=5)

Only the border edge of the toggle button changes to a red color, and
not the background of the text area background color (which remains,
on my Windows 7 box, blue).

Using wxPython 2.9.1.1 and Python 2.7 on a Windows 7 box.

Is this expected behavior or is it a bug?

I'd use wx.lib.buttons.GenToggleButton, except IT has problems with
multi-line text.

troubles, troubles...
Chris.

Robin Dunn

unread,
Nov 27, 2010, 3:37:02 PM11/27/10
to wxpytho...@googlegroups.com
On 11/27/10 11:15 AM, Chris Spencer wrote:
> In the wxPython Demo, if you change this...
> for word in "These are toggle buttons".split():
> b = wx.ToggleButton(panel, -1, word)
> self.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggle, b)
> buttons.Add(b, flag=wx.ALL, border=5)
>
> to this...
>
> for word in "These are toggle buttons".split():
> b = wx.ToggleButton(panel, -1, word)
> b.SetBackgroundColour(wx.Colour(255,0,0))
> self.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggle, b)
> buttons.Add(b, flag=wx.ALL, border=5)
>
> Only the border edge of the toggle button changes to a red color, and
> not the background of the text area background color (which remains,
> on my Windows 7 box, blue).
>
> Using wxPython 2.9.1.1 and Python 2.7 on a Windows 7 box.
>
> Is this expected behavior or is it a bug?

Expected. Since XP the native Windows button draws fixed textures over
the window's background, so I guess you could say that the entire button
is in the foreground. Last I checked the native widget doesn't pay any
attention to the foreground color either.

For wxButton wx puts the button into owner-drawn mode when the colors
are set, and then wx draws the button itself and doesn't let the native
button draw anything. I guess that same thing was not done with
wx.ToggleButton,

>
> I'd use wx.lib.buttons.GenToggleButton, except IT has problems with
> multi-line text.


You can implement a DrawLabel method in a derived class and then draw
the contents of the button however you like if the default doesn't meet
your needs.


--
Robin Dunn
Software Craftsman
http://wxPython.org

Reply all
Reply to author
Forward
0 new messages