gpt4 book ai didi

python - 记事本每帧上关闭应用程序的 wxPython 按钮

转载 作者:行者123 更新时间:2023-11-30 23:34:31 26 4
gpt4 key购买 nike

我有一个 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。我该怎么做?

最佳答案

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

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

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

关于python - 记事本每帧上关闭应用程序的 wxPython 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18053539/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com