Guys, I am trying to change the background color of my window in WxPython.
Here is what I got:
Why doesn't it work?

import wx

class my_window(wx.Frame):
    
    def __int__(self, parent, id):
        wx.Frame.__int__(self,parent,id,'My Window', size=(300,200))
        self.Colours()

    
    def Colours(self):
        self.pnl1.SetBackgroundColour(wx.BLACK)
        


if __name__ == "__main__":
    app=wx.PySimpleApp()
    frame=my_window(parent=None,id=-1)
    frame.Show()
    app.MainLoop()
import wx

class my_window(wx.Frame):
    def __init__(self, parent, id):  #error __int__
        wx.Frame.__init__(self,parent,id,'My Window', size=(300,200))

        #Panel for frame
        self.panel = wx.Panel(self)
        self.SetBackgroundColour('blue')

if __name__ == "__main__":
    app=wx.PySimpleApp()
    frame=my_window(parent=None,id=-1)
    frame.Show()
    app.MainLoop()
import wx

class my_window(wx.Frame):
    def __init__(self, parent, id):  #error __int__
        wx.Frame.__init__(self,parent,id,'My Window', size=(300,200))

        #Panel for frame
        self.panel = wx.Panel(self)
        self.SetBackgroundColour('blue')

if __name__ == "__main__":
    app=wx.PySimpleApp()
    frame=my_window(parent=None,id=-1)
    frame.Show()
    app.MainLoop()

snippsat when I ran your code I got the same result with yours that I did with mine.
Just a gray window pops up.

It work fine for me,it has no error so it should work for you to.
In your first code both __int__ statement was wrong should be __init__

import wx

class my_window(wx.Frame):
    def __init__(self, parent, id):
        wx.Frame.__init__(self,parent,id,'My Window', size=(300,200))
    
        self.SetBackgroundColour('BLACK')

if __name__ == "__main__":
    app=wx.PySimpleApp()
    frame=my_window(parent=None,id=-1)
    frame.Show()
    app.MainLoop()

Thanks snippsat I got it to work.
It wouldn't work when I ran it with:

#Panel for frame
self.panel = wx.Panel(self)

and also __int__ instead of __init__ like you said :)


Here is my final code:

import wx
       
class my_window(wx.Frame):
      
    def __init__(self, parent, id):
        wx.Frame.__init__(self,parent,id,'My Window', size=(300,200))
        self.SetBackgroundColour(wx.BLUE)
       
if __name__ == "__main__":
      app=wx.PySimpleApp()
      frame=my_window(parent=None,id=-1)
      frame.Show()
      app.MainLoop()

When you added the panel, you didn't call SetBackgroundColour on the panel, but you were still using the Frame's method. Instead of:

    #Panel for frame
    self.panel = wx.Panel(self)
    self.SetBackgroundColour('blue')

It should be:

    #Panel for frame
    self.panel = wx.Panel(self)
    self.panel.SetBackgroundColour('blue')
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.