Jesh Kundem
Jesh Kundem

Reputation: 974

wxpython button background color to default

I am looking to change the background color of a button in my GUI application to default.After searching online, i saw that

button1.SetBackgroundColour(wx.NullColor) does not seem to work. I am using python 2.7.

Is there any other way I could set it to default color with out using system colors

Upvotes: 1

Views: 6204

Answers (4)

Jan Bodnar
Jan Bodnar

Reputation: 11637

I think that the solutions do not work because wxPython works with a style system. I was able to change foreground & background colours with the SetStyle method.

I was styling a wx.TextCtrl where I needed to highlight the text I search for.

First, I stored the existing colours to variables.

bc = self.te.GetBackgroundColour()
fc = self.te.GetForegroundColour()

self.bcol = wx.Colour(bc[0], bc[1], bc[2], bc[3])
self.fcol = wx.Colour(fc[0], fc[1], fc[2], fc[3])

Change the colours with SetStyle

self.te.SetStyle(x, y, wx.TextAttr(wx.BLACK, wx.LIGHT_GREY))

And reset it back to the original colours:

self.te.SetStyle(0, -1, wx.TextAttr(self.fcol, self.bcol)) 

Upvotes: 0

user15224111
user15224111

Reputation: 1

With Python 2.7.17 and wxPython 3.0.2.0 the following seems to work:

button1.SetBackgroundColour('')

Upvotes: 0

Soyding Mete
Soyding Mete

Reputation: 166

If wx.NullColour doesn't work, a solution is to decode the RGB code for the colour you seek and apply it to your background.

E.g. the background color on my wx GUI is the light grey from Windows, its RGB code is R=240, G=240, B=240 (you can measure this using Paint for instance).

Then this should work:

button1.SetBackgroundColour(wx.Colour(240, 240, 240))

Of course if you want your GUI to be portable on other systems this isn't the best option since this light grey is only the default colour in Windows.

Upvotes: 2

lira
lira

Reputation: 59

A little late, but maybe someone else has the same problem. Did you try

button1.SetBackgroundColour(wx.NullColour) 

So, write "Colour" instead of "Color", the non-American writing. This worked for me.

Upvotes: 5

Related Questions