wxPython面板现在显示颜色

时间:2018-03-31 13:44:59

标签: python wxpython panel frame wxwidgets

我正在wxPython中编写一个应用程序,当我去运行应用程序时,我希望看到2个不同颜色的面板,但我不会。 有人可以告诉我为什么吗?

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

1 个答案:

答案 0 :(得分:0)

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

尝试上面的代码。