English 中文(简体)
为什么不能在单击关闭窗口后退出应用程序
原标题:why cannot i exit app after click on the close window

应用程序非常简单, 只有两个窗口: 当我点击“ 坚固” 搜索 < / 坚固” 按钮时, 新窗口会显示出来 。 但是当我逐个关闭孩子和父窗口时, 我发现该应用程序根本不退出( 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()

如需帮助,请致谢。

最佳回答

首先, 您正在程序里启动两个 wx 应用程序和主 Loop 。 这不需要 。

修改 :

    app2 = wx.App()
    frame2 = Output(self,u result )
    frame2.Show()
    app2.MainLoop()

    frame2 = Output(self,u result )
    frame2.Show()

The Living Dead seems to be the MessageDialog that is working in its own loop. You can fix this nasty problem in two ways:

1. 不犹豫不决,无情地杀死它:

    if dlg.ShowModal() == wx.ID_YES:
        dlg.Destroy()
        self.Destroy()

2.- Better, make it a child of the frame in order to be automatically and fully killed, 与out possibility of resuscitation in any creepy form, when the frame is closed (Note the self):

     dlg = wx.MessageDialog(self, msg, "Wait ...", wx.YES_NO|wx.ICON_EXCLAMATION)
问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签