self.label.SetBackgroundColour not setting colours

My previous post has been resolved and can be marked closed- I needed to switch the order of my procedures so that it was defined before it was called.

I can also close it once it is posted to the forum.

Now I am not getting any errors but I am unable to change the on the dialog box -see bolded lines below:

class decode_dialog_wx(wx.Frame):
def OnButtonClick(self,event):
print “You Clicked the Button”
def OnPressEnter(self,event):
print “You pressed Enter”
def init(self,parent,id,title):
wx.Frame.init(self,parent,id,title)
self.parent = parent
self.initialize()

def initialize(self):
sizer = wx.GridBagSizer()
self.entry = wx.TextCtrl(self,-1,value=u"Enter File Name")
sizer.Add(self.entry,(0,0),(1,1),wx.EXPAND)
self.Bind(wx.EVT_TEXT_ENTER,self.OnPressEnter,self.entry)
button = wx.Button(self,-1,label=“Click me!”)
sizer.Add(button, (0,1))
self.Bind(wx.EVT_BUTTON, self.OnButtonClick, button)
self.label = wx.StaticText(self,-1,label=u’Hello !’)
self.label.SetBackgroundColour(wx.BLUE)
self.label.SetForegroundColour(wx.RED)
sizer.Add(self.label,(1,0),(1,2),wx.EXPAND )
self.Refresh()

sizer.AddGrowableCol(0)
self.SetSizerAndFit(sizer)
self.SetSizeHints(-1,self.GetSize().y,-1,self.GetSize().y );
self.Show(True)

if name == ‘main’:
app = wx.App()
frame = decode_dialog_wx(None,-1,‘Decoder’)
app.MainLoop()
main()

The dialog box shows the text as RED but the background is the original grey.

I am running CENTOS 6.5 with Python 2.6.6

I am sure that it is something simple but I am not getting errors to help me along :frowning:

Thanks in advance!

Hi John,

My previous post has been resolved and can be marked closed- I needed to switch the order of my procedures so that it was defined before it was called.

The sequence of defining your methods is not important, the methods "OnPressEnter" and "OnButtonClick" just have to be within your "decode_dialog_wx" class. Maybe you had them not at the correct indentation level, so they where 'outside' your class.

I can also close it once it is posted to the forum.

BTW, this is a mail list, you can't close posts, it is enough to just post in the thread mentioning that you solved your problem.

Now I am not getting any errors but I am unable to change the on the dialog box -see bolded lines below:

Strange this works for me, but I am on Windows.

What wxPython version are you using?

If you just start with wxPython/Python I would suggest to upgrade to Python 2.7.8 and wxPython at a minimum 2.8.12.

BTW, are you not getting an error when you run your code on the line "main()"?

I would also suggest to attach the code as many email clients cause havoc with the indentation.

Werner

···

On 7/13/2014 2:26, John wrote:

Hi Werner,

Sorry about pasting the code

I needed to put the color in quotes such as “Yellow” etc and it worked :-~

My wxPython is version is: 2.8.12.0 (gtk2-unicode) which is okay.

I only have Python 2.6.6 and that is all I see in the CentOS repository.

Do you know I would upgrade Python in Centos if there is no RPM for it?

I tried to compile and install 2.7.6 but then it could find wxPython.

2.6 is still on my system so I reverted back to it.

Guidance is much apprecaited!

-John

···

On Sunday, July 13, 2014 2:40:22 AM UTC-6, werner wrote:

Hi John,

On 7/13/2014 2:26, John wrote:

My previous post has been resolved and can be marked closed- I needed
to switch the order of my procedures so that it was defined before it
was called.

The sequence of defining your methods is not important, the methods
“OnPressEnter” and “OnButtonClick” just have to be within your
“decode_dialog_wx” class. Maybe you had them not at the correct
indentation level, so they where ‘outside’ your class.

I can also close it once it is posted to the forum.

BTW, this is a mail list, you can’t close posts, it is enough to just
post in the thread mentioning that you solved your problem.

Now I am not getting any errors but I am unable to change the on the
dialog box -see bolded lines below:

Strange this works for me, but I am on Windows.

What wxPython version are you using?

If you just start with wxPython/Python I would suggest to upgrade to
Python 2.7.8 and wxPython at a minimum 2.8.12.

BTW, are you not getting an error when you run your code on the line
“main()”?

I would also suggest to attach the code as many email clients cause
havoc with the indentation.

Werner

Alternatively you could have used wx.YELLOW as your colour.

···

On 13/07/14 23:23, John wrote:

Hi Werner,

Sorry about pasting the code

I needed to put the color in quotes such as "Yellow" etc and it worked :-~

Hi John,

...

I only have Python 2.6.6 and that is all I see in the CentOS repository.

Do you know I would upgrade Python in Centos if there is no RPM for it?

I don't but using Google I found this:

I tried to compile and install 2.7.6 but then it could find wxPython.

If you try it again do it with 2.7.8 IIRC it has a few security fixes.

When one installs a new Python version then you most often need to install things again to that version, I think you always have to do that if the major or minor number changes, i.e. 2.6 to 2.7, but at least on Windows I didn't have to do it to go from 2.7.6 to 2.7.8.

2.6 is still on my system so I reverted back to it.

It sounds like 2.6 is the System Python version on CentOS, so you should leave that alone.

Werner

···

On 7/14/2014 0:23, John wrote:

I think you just need to add style=wx.TE_RICH when you instantiate wx.TextCtrl.

···

On Saturday, July 12, 2014 5:26:03 PM UTC-7, John wrote:

My previous post has been resolved and can be marked closed- I needed to switch the order of my procedures so that it was defined before it was called.

I can also close it once it is posted to the forum.

Now I am not getting any errors but I am unable to change the on the dialog box -see bolded lines below:

class decode_dialog_wx(wx.Frame):
def OnButtonClick(self,event):
print “You Clicked the Button”
def OnPressEnter(self,event):
print “You pressed Enter”
def init(self,parent,id,title):
wx.Frame.init(self,parent,id,title)
self.parent = parent
self.initialize()

def initialize(self):
sizer = wx.GridBagSizer()
self.entry = wx.TextCtrl(self,-1,value=u"Enter File Name")
sizer.Add(self.entry,(0,0),(1,1),wx.EXPAND)
self.Bind(wx.EVT_TEXT_ENTER,self.OnPressEnter,self.entry)
button = wx.Button(self,-1,label=“Click me!”)
sizer.Add(button, (0,1))
self.Bind(wx.EVT_BUTTON, self.OnButtonClick, button)
self.label = wx.StaticText(self,-1,label=u’Hello !')
self.label.SetBackgroundColour(wx.BLUE)
self.label.SetForegroundColour(wx.RED)
sizer.Add(self.label,(1,0),(1,2),wx.EXPAND )
self.Refresh()

sizer.AddGrowableCol(0)
self.SetSizerAndFit(sizer)
self.SetSizeHints(-1,self.GetSize().y,-1,self.GetSize().y );
self.Show(True)

if name == ‘main’:
app = wx.App()
frame = decode_dialog_wx(None,-1,‘Decoder’)
app.MainLoop()
main()

The dialog box shows the text as RED but the background is the original grey.

I am running CENTOS 6.5 with Python 2.6.6

I am sure that it is something simple but I am not getting errors to help me along :frowning:

Thanks in advance!

Hi Steve,

That is what I first tried was "wx.Yellow and that did not work. When I used “Yellow” and moved the def to the top of the class it started working.

From what I understand the order should not have been a problem.

Is the wx.YELLOW case sensitive?

If so that might have been the problem.

Thanks so much for your thoughts!

-John

···

On Sunday, July 13, 2014 11:00:11 PM UTC-6, Gadget Steve wrote:

On 13/07/14 23:23, John wrote:

Hi Werner,

Sorry about pasting the code

I needed to put the color in quotes such as “Yellow” etc and it worked :-~

Alternatively you could have used wx.YELLOW as your colour.

Hi Steve,

Answered by own question - these worked…

self.SetBackgroundColour("Blue")
self.SetBackgroundColour(wx.BLUE)

Good to know - now to get to what I was trying to do :slight_smile:

Thanks for the guidance!!

-John

···

On Monday, July 14, 2014 4:54:09 PM UTC-6, John wrote:

Hi Steve,

That is what I first tried was "wx.Yellow and that did not work. When I used “Yellow” and moved the def to the top of the class it started working.

From what I understand the order should not have been a problem.

Is the wx.YELLOW case sensitive?

If so that might have been the problem.

Thanks so much for your thoughts!

-John

On Sunday, July 13, 2014 11:00:11 PM UTC-6, Gadget Steve wrote:

On 13/07/14 23:23, John wrote:

Hi Werner,

Sorry about pasting the code

I needed to put the color in quotes such as “Yellow” etc and it worked :-~

Alternatively you could have used wx.YELLOW as your colour.

John,
Just a general point - in python/C/C++/lots of
others is case sensitive - the only things that are not are deliberately aliased by the developer, (but sometimes thing, Thing
& THING all exist but are not the same thing e.g.: thing might
be a package, Thing the main class and THING a constant), are being parsed from a string and the developer has taken the
trouble to add a tolower() or toupper() to the code to make it case
independent. Personally, I think that having different case aliases
constitutes code bloat, reusing the same name in a different case
can lead to confusion and that the last is good practice not would agree with me.
Gadget/Steve

···

On 15/07/14 00:18, John wrote:

Hi Steve,

    Answered by own question - these worked...



        self.SetBackgroundColour("Blue")

        self.SetBackgroundColour(wx.BLUE)



    Good to know - now to get to what I was trying to do :-)



    Thanks for the guidance!!



    -John





    On Monday, July 14, 2014 4:54:09 PM UTC-6, John wrote:

Hi Steve,

        That is what I first tried was "wx.Yellow and that did not

work. When I used “Yellow” and moved the def to the top of
the class it started working.

        From what I understand the order should not have been a

problem.

        Is the wx.YELLOW case sensitive?



        If so that might have been the problem.



        Thanks so much for your thoughts!



        -John

**everythingeitherorbuteverybody

Hi John,

Hi Steve,

That is what I first tried was "wx.Yellow and that did not work. When I used "Yellow" and moved the def to the top of the class it started working.

From what I understand the order should not have been a problem.

Is the wx.YELLOW case sensitive?

Yes
import wx
wx.YELLOW
wx.Colour(-1, -1, -1, 255)
wx.Yellow
Traceback (most recent call last):
   File "<string>", line 1, in <fragment>
builtins.AttributeError: 'module' object has no attribute 'Yellow'

If so that might have been the problem.

but you would have gotten an AttributeError

Werner

···

On 7/15/2014 0:54, John wrote: