单击关闭按钮python后,程序的执行不会结束(使用wxpython-GUI)

时间:2010-11-30 17:11:24

标签: python user-interface wxpython

我使用python创建了一个cpu调度程序应用程序,我使用wxpython创建一个只包含一个连续更新的大文本区域的框架,问题是单击关闭按钮(x)将关闭框架但是另一个或多个帧会再次出现并且程序继续执行,下面是接口代码。

class Interface(wx.Frame):
    def __init__(self , par , id):
        wx.Frame.__init__(self , par , id , 'XP simulator' , size=(200 , 200 ))
        panel = wx.Panel(self)
        self.sel = 30
        centerPanel = wx.Panel(panel, -1 , size=(100,100) , pos=(50,30))
        self.cpu = CPU(centerPanel, -1)


    def prnt(string , frm):
        print string

    if __name__ =="__main__":

        mutex = threading.Semaphore()
        full = threading.Semaphore(0)
        empty = threading.Semaphore(30)

        buff = util.Queue()
        prod = util.Producer(buff , mutex , empty , full)

        app = wx.App()
        frame = Interface(None, -1)
        frame.Show()

        prod.start()
        print "produced"
        time.sleep(1)
        xp = sched.XPsched(buff , mutex , full , empty, prnt, frame)
        xp.start()

        app.MainLoop()

感谢;) NATALY ..

1 个答案:

答案 0 :(得分:1)

您必须在wxFrame中绑定close事件:

self.Bind(wx.EVT_CLOSE, self.on_close)

然后添加一个on_close方法:

def on_close(self, event):
    self.Destroy()
    sys.exit(0)