Nataly
Nataly

Reputation: 307

Program's execution does not end after clicking the close button python (using wxpython-GUI)

I've made a cpu scheduler application using python , i used wxpython to make a frame containing merely a big text area that is updated continously , the problem is that clicking the close button (x) would close the frame but another or multiple frames would appear again and the program continues execution , below is the interface code.

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()

Thanks;) Nataly..

Upvotes: 1

Views: 814

Answers (1)

nmichaels
nmichaels

Reputation: 51029

You have to bind the close event in your wxFrame:

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

then add an on_close method:

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

Upvotes: 1

Related Questions