I am trying to develop a Dialog that asks a question, stores it and return the answer when asked.
This code below works, but my main issue is that I am not being to finish the application opened by wxPython… The Dialog itself disappears but the python icon is still in my taskbar (I am using Mac - High Sierra).
You will see below that I am trying all the codes (that I know of) to close it… Destroy, del, Close, EndModal, Exit, even sys.exit
Can anyone help me to close the application?? Is there something wrong with my code?
class YesNoDialog(wx.Dialog):
def init(self, app):
wx.Dialog.init(self, None, -1, style=wx.DEFAULT_DIALOG_STYLE, title=“TOOL”)
windowSizer = wx.GridBagSizer(1,1)
windowSizer.Add(wx.StaticText(self, -1, “Do you want to continue?”), (0, 0), span=(1, 10), flag=wx.ALL, border=10)
yes = wx.Button(self, -1, "Yes", size=(50, 30))
no = wx.Button(self, -1, "No", size=(50, 30))
windowSizer.Add(yes, (1, 0), flag=wx.ALL, span=(1, 2), border=10)
windowSizer.Add(no, (1, 3), span=(1, 3), flag=wx.ALL, border=10)
yes.Bind(wx.EVT_BUTTON, lambda event: self.stop(event, 1))
no.Bind(wx.EVT_BUTTON, lambda event: self.stop(event, 2))
self.Bind(wx.EVT_CLOSE, lambda event: app.Exit())
self.SetSizerAndFit(windowSizer)
self.Center()
def stop(self, event, step):
self.EndModal(step)
self.Close()
self.Destroy()
event.skip()
``
class StepDialog(wx.Dialog):
def init(self):
self.app = wx.App(0)
self.app.MainLoop()
self.step = YesNoDialog(self.app).ShowModal()
def tearDown(self):
sys.exit(0)
def getStep(self):
self.step.Exit()
wx.CallLater(5, self.tearDown())
self.step.Destroy()
self.Destroy()
self.app.Exit()
self.app.ExitMainLoop()
del self.app
return self.step
``
main.py
def main():
step = StepDialog().getStep()
``