Opening a new window when we click on a button in wx python
Question: I am new to python . I want to open a new window when I click on button OK. I
am having the following code but getting error. I googled it but got few
answers but didn't get that how to make it work

    
    
    import wx
    
    class MyFrame(wx.Frame):
    
        def __init__(self):
            wx.Frame.__init__(self, None, -1, "My Frame", size=(3000, 3000))
            panel = wx.Panel(self,-1)
            #panel.Bind(wx.EVT_MOTION,  self.OnMove)
            wx.StaticText(panel, -1, "What are the values of X", pos=(10, 12))
            #self.posCtrl = wx.TextCtrl(panel, -1, "", pos=(100, 10))
            wx.CheckBox(panel, -1, "Apples", (20,100), (160,-1))
            wx.CheckBox(panel, -1, "Mango", (20,150), (160,-1))
            wx.CheckBox(panel, -1, "Banana", (20,200), (160,-1))
            wx.CheckBox(panel, -1, "Orange", (20,250), (160,-1))
            button=wx.Button(panel,label="OK",pos=(800, 400), size = (50,50))
            self.Bind(wx.EVT_BUTTON, self.newwindow, button)
    
        # def OnMove(self, event):
            # pos = event.GetPosition()
            # self.posCtrl.SetValue("%s, %s" % (pos.x, pos.y))
    
    
        def newwindow(self, event):
            secondWindow = window2()
            secondWindow.Show()
    
    
    class window2(wx.Frame):
    
        title = "new Window"
    
        def __init__(self,parent,id):
            wx.Frame.__init__(self, id,'Window2', size=(1000,700))
            panel=wx.Panel(self, -1)
    
            self.SetBackgroundColour(wx.Colour(100,100,100))
            self.Centre()
            self.Show()
    
    app = wx.App(False)
    frame = MyFrame()
    frame.Show(True)
    app.MainLoop()
    

Error that I am getting when click on OK button

    
    
    Traceback (most recent call last):
      File "gui_quiz.txt", line 36, in newwindow
        secondWindow = window2()
    TypeError: __init__() takes exactly 3 arguments (1 given)
    


Answer: the answer is in the traceback. your `window2` class `__init__` function
requires `(self,parent,id)`. self is provided already (behind the scene) and
that's why `1 given`.

So you will have to provide other two parameters (`parent` and `id`). `Parent`
here can be just `self` (recommended, if you want to close this frame from the
main frame etc) or `None` otherwise and `id` can be just `-1` to leave out for
wx to set it for you. if you plan to have many frames then setting id will
help you keep track of them.

