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()

Edited 5 Years Ago by snippsat: n/a

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()

Edited 5 Years Ago by HoneyBadger: n/a

This question has already been answered. Start a new discussion instead.