简体   繁体   中英

WXPYTHON - How Do I Get Users Input in a MessageDialog?

Here's my code:

def Quit(self, e):
    suremsg = wx.MessageDialog(None, "Are you sure you want to close the program?","Are you sure?", wx.YES_NO | wx.ICON_QUESTION).ShowModal()

def Close(self):
    self.Close()

I'm technically wanting the program to close if the user clicks YES, and closes the MessageDialog and refuses to close if the user clicks NO.

Alright, I went for a little surf through many articles that explain how I can get the result of the user's input.

So, I switched my code to this:

   def Quit(self, e):
    suremsg = wx.MessageDialog(None, "Are you sure you want to close the program?","Are you sure?", wx.YES_NO | wx.ICON_QUESTION)
    result = suremsg.ShowModal()
    if result == wx.ID_YES:
       self.Close()
    else:
       suremsg.Destroy()

And it worked like a charm!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM