Search code examples
pythonwxpythonpanelframewxwidgets

wxPython panel now showing colour


I am writing an application in wxPython, when i go to run the application i expect to see 2 different colored panels but i dont. Can someone tell me why ?

import wx



class Frame(wx.Frame):
    def __init__(self, *args, **kwargs):
        super(Frame, self).__init__(*args, **kwargs)
        self.Center()
        self.Show()

        panel1 = Panel1(self,-1,size=(200,200),pos=(0,0))
        panel2 = Panel2(self,-1,size=(200,200),pos=(210,0))        



class Panel1(wx.Panel):
    def __init__(self, *args, **kwargs):
        super(Panel1,self).__init__(*args, **kwargs)
        self.SetBackgroundColour("PURPLE")

class Panel2(wx.Panel):
    def __init__(self, *args, **kwargs):
        super(Panel2,self).__init__(*args, **kwargs)
        self.SetBackgroundColour("RED")        


if __name__ == "__main__":
    app = wx.App()
    Frame(None,title="MY_PROJECT",size=(500,600))
    app.MainLoop()

Solution

  • import wx
    
    
    
    class Frame(wx.Frame):
        def __init__(self, *args, **kwargs):
            super(Frame, self).__init__(*args, **kwargs)
            self.Center()
    
    
            panel1 = Panel1(self,-1,size=(200,200),pos=(0,0))
            panel2 = Panel2(self,-1,size=(200,200),pos=(210,0))        
    
            self.Show()
    
    class Panel1(wx.Panel):
        def __init__(self, *args, **kwargs):
            super(Panel1,self).__init__(*args, **kwargs)
            self.SetBackgroundColour("PURPLE")
    
    class Panel2(wx.Panel):
        def __init__(self, *args, **kwargs):
            super(Panel2,self).__init__(*args, **kwargs)
            self.SetBackgroundColour("RED")        
    
    
    if __name__ == "__main__":
        app = wx.App()
        Frame(None,title="MY_PROJECT",size=(500,600))
        app.MainLoop()
    

    Try with above code.