0

アプリは非常にシンプルで、2 つのウィンドウしかありません。検索ボタンをクリックすると、新しいウィンドウが表示されます。しかし、子ウィンドウと親ウィンドウを1つずつ閉じると、アプリがまったく終了しないことがわかりました(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()

助けていただければ幸いです。

4

1 に答える 1

2

まず、プログラムで 2 つの wx.Applications と mainLoops を開始します。これは必要ありません。

変更:

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

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

Living Deadは、独自のループで動作している MessageDialog のようです。この厄介な問題は、次の 2 つの方法で解決できます。

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)
于 2012-05-24T07:02:49.177 に答える