0

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()
2
Contributors
4
Replies
15
Views
6 Years
Discussion Span
Last Post by HoneyBadger
Featured Replies
  • It work fine for me,it has no error so it should work for you to. In your first code both [B]__int__[/B] statement was wrong should be [B]__init__[/B] [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('BLACK') if __name__ == "__main__": app=wx.PySimpleApp() frame=my_window(parent=None,id=-1) frame.Show() app.MainLoop()[/CODE] Read More

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

1

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 by snippsat: n/a

0

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 by HoneyBadger: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.