I need a dialog that can return two values "Yes" or “No”. I want that when closing the dialog (pressing X
or Esc
), the return result is wx.ID_NO
.
I am using self.SetEscapeId(wx.ID_NO)
for this.
But when I close the dialog not through the “Yes” button, I always get wx.ID_CANCEL
. Why?
Example:
import wx
class Dialog(wx.Dialog):
def __init__(self, parent):
super().__init__(parent, title='Dialog', style=wx.CAPTION)
self.SetAffirmativeId(wx.ID_YES)
self.SetEscapeId(wx.ID_NO) # <---
sizer = self.CreateButtonSizer(wx.YES_NO)
sizer.Fit(self)
self.SetSizer(sizer)
class Frame(wx.Frame):
def __init__(self):
super().__init__(None)
def callback():
with Dialog(self) as dlg:
answer = dlg.ShowModal()
print(answer == wx.ID_YES,
answer == wx.ID_NO,
answer == wx.ID_CANCEL,
sep='\n')
wx.CallAfter(callback)
if __name__ == '__main__':
app = wx.App()
Frame().Show()
app.MainLoop()
Windows 10, wxPython 4.1.1 (and 4.0.7.post2), Python 3.7.9.