New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SetBackgroundColour/SetForegroundColour reset Button style #815

Froyok opened this Issue Apr 15, 2018 · 5 comments


None yet
3 participants

Froyok commented Apr 15, 2018

Operating system: Windows 7 x64 (SP2)
wxPython version: 4.0.1
Stock or custom build: Stock (installed via pip)
Python version: Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45)
Stock or custom build: Stock

Description of the problem :
When setting a custom foreground or background color on a button, the specified text layout for the label is ignored and will default back to centered. If no colors are specified, everything works fine. See example below.
I observed the issue via the wxGlade preview, but is also happen even when running the code as standalone.

Minimal app to reproduce :

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# generated by wxGlade 0.8.0 on Sun Apr 15 16:21:17 2018

import wx

class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.SetSize((400, 300))
        self.button_1 = wx.Button(self, wx.ID_ANY, "button_1\nMultiline", style=wx.BU_LEFT | wx.BU_TOP)
        self.button_2 = wx.Button(self, wx.ID_ANY, "button_1\nMultiline", style=wx.BU_LEFT | wx.BU_TOP)
        self.button_3 = wx.Button(self, wx.ID_ANY, "button_1\nMultiline", style=wx.BU_LEFT | wx.BU_TOP)


    def __set_properties(self):
        self.button_1.SetMinSize((170, 60))
        self.button_2.SetMinSize((170, 60))
        self.button_2.SetBackgroundColour(wx.Colour(255, 0, 0))
        self.button_3.SetMinSize((170, 60))

    def __do_layout(self):
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_1.Add(self.button_1, 0, 0, 0)
        sizer_1.Add(self.button_2, 0, 0, 0)
        sizer_1.Add(self.button_3, 0, 0, 0)

class MyApp(wx.App):
    def OnInit(self):
        self.frame = MyFrame(None, wx.ID_ANY, "")
        return True

if __name__ == "__main__":
    app = MyApp(0)

The code above produce the following for me :

@RobinD42 RobinD42 added the wxWidgets label May 6, 2018


This comment has been minimized.


RobinD42 commented May 6, 2018

This is a wxWidgets issue. IIRC when you change the colors of a button it switches to owner-drawn mode and is no longer drawn by the native control. wxWidgets can probably be modified to correct this difference, but you'll need to submit a ticket to


This comment has been minimized.

Froyok commented May 7, 2018

Thanks !
I have reported it, it's available here :


This comment has been minimized.


swt2c commented May 7, 2018

Looks like VZ fixed it already:


This comment has been minimized.


RobinD42 commented May 9, 2018

I'm updating the submodule link now...


This comment has been minimized.


RobinD42 commented May 9, 2018

Closed by #847

@RobinD42 RobinD42 closed this May 9, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment