该应用程序非常简单,只有两个窗口:当我点击搜索按钮时,会显示一个新窗口。但当我一个接一个地关闭孩子和父窗口时,我发现应用程序根本没有退出(IDLE告诉我仍然有东西在运行)
#coding=utf8
import wx
SearchResult = ""
Name = ""
minPrice = 0
maxPrice = 0
class Output(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self,parent,-1,title,size = (300,600))
panel2 = wx.Panel(self,-1)
Result = wx.StaticText(panel2,-1,SearchResult,pos = (20,20),size=(260,560))
self.Bind(wx.EVT_CLOSE, self.OnAppClose)
def OnAppClose(self, evt):
msg = "Hold on there a minute"
dlg = wx.MessageDialog(None, msg, "Wait ...",
wx.YES_NO | wx.ICON_EXCLAMATION)
if dlg.ShowModal() == wx.ID_YES:
self.Destroy()
else:
return
dlg.Destroy()
class TextCtrlFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,-1,u'crawl',size = (600,300))
panel = wx.Panel(self,-1)
Label1 = wx.StaticText(panel,-1,u"name",pos = (30,20))
self.inputText1 = wx.TextCtrl(panel,-1,"",pos = (90,20),size=(150,-1))
self.inputText1.SetInsertionPoint(0)
Label2 = wx.StaticText(panel,-1,u"price",pos = (270,20))
self.inputText2 = wx.TextCtrl(panel,-1,"",pos = (330,20),size=(60,-1))
Label3 = wx.StaticText(panel,-1,"----",pos = (400,20))
self.inputText3 = wx.TextCtrl(panel,-1,"",pos = (430,20),size=(60,-1))
self.button = wx.Button(panel, -1, u"search",pos = (250,230))
self.Bind(wx.EVT_BUTTON,self.OnClick,self.button)
def OnClick(self,event):
Name = self.inputText1.GetValue()
minPrice = self.inputText2.GetValue()
maxPrice = self.inputText3.GetValue()
SearchResult = Name + minPrice + maxPrice
app2 = wx.App()
frame2 = Output(self,u'result')
frame2.Show()
app2.MainLoop()
if __name__ == "__main__":
app = wx.App()
frame = TextCtrlFrame()
frame.Show()
app.MainLoop()
任何帮助表示感谢。
答案 0 :(得分:2)
首先,您在程序中启动了两个wx.Applications和mainLoops。这不是必需的。
修改:
app2 = wx.App()
frame2 = Output(self,u'result')
frame2.Show()
app2.MainLoop()
与
frame2 = Output(self,u'result')
frame2.Show()
活着的死亡似乎是在自己的循环中工作的MessageDialog。 您可以通过两种方式解决这个令人讨厌的问题:
1.-不要犹豫,毫不犹豫地杀死它:
if dlg.ShowModal() == wx.ID_YES:
dlg.Destroy()
self.Destroy()
2.-更好,让它成为框架的孩子,以便在框架关闭时自动完全杀死,不会以任何令人毛骨悚然的形式进行复苏(注意self
):
dlg = wx.MessageDialog(self, msg, "Wait ...", wx.YES_NO|wx.ICON_EXCLAMATION)