1

我有一个wxpython班级 Neoprobe,它有 3 个班级/笔记本页面

class Neoprobe(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title="Neoprobe QC Application",size=(750,900))


        # Here we create a panel and a notebook on the panel
        panel = wx.Panel(self)
        nb = wx.Notebook(panel)

        # create the page windows as children of the notebook
        page1 = Sensitivity(nb)
        page2 = Angular(nb)
        page3 = Distance(nb)

        # add the pages to the notebook with the label to show on the tab
        nb.AddPage(page1, "Sensitivity")
        nb.AddPage(page2, "Angular")
        nb.AddPage(page3, "Distance")

我想要一个关闭笔记本每一页上的应用程序的退出按钮。例如,在“Angular”页面中,我有以下代码

class Angular(wx.Panel):
    def __init__(self, parent):
    .
    .
    .

        hbox2 = wx.BoxSizer(wx.HORIZONTAL)
        graph_btn = wx.Button(top_panel, label='Plot', size=(70, 30))
        hbox2.Add(graph_btn)
        db_btn = wx.Button(top_panel, label='Update db', size=(100, 30))
        hbox2.Add(db_btn, flag=wx.LEFT|wx.BOTTOM, border=5)
        exit_btn = wx.Button(top_panel, label='Exit', size=(70, 30))
        hbox2.Add(exit_btn, flag=wx.LEFT|wx.BOTTOM, border=5)
        top_panel_sizer.Add(hbox2, flag=wx.ALIGN_RIGHT|wx.RIGHT, border=10)

        #Setup button bindings
        self.Bind(wx.EVT_BUTTON, self.OnExit, exit_btn)

        def OnExit(self,event):
            dlg = wx.MessageDialog(self,
               "Do you really want to close this application?",
               "Confirm Exit", wx.OK|wx.CANCEL|wx.ICON_QUESTION)
            result = dlg.ShowModal()
            dlg.Destroy()
            if result == wx.ID_OK:
                self.Close()

但是,这(显然)不会关闭 wx.Frame。我该怎么做呢?

4

1 回答 1

3

如果您试图关闭应用程序,那么您需要调用以下内容:

top = wx.GetApp().GetTopWindow()
top.Close()

编辑: 更正了使用静态 wx.GetApp() 检索应用程序的代码。

于 2013-08-05T11:05:33.227 回答