How can i get a value from button click from my frame?
btnYes = wx.Button(panel, -1, "OK")
self.Bind(wx.EVT_BUTTON, self.clickYes, btnYes)
def clickYes(self, evt):
print "clicked Yes"
self.Close()
whenever a user click yes , i want to get a value to check in other module. Something like confirmation flag. When user is confirmed one item then carrying on doing other items. The confirmation flag i will be using is here below :
def my_methodABC():
matchList = []
for x, y in product(d1rows, d2rows):
if userConfirmedFromWxPythonClickYesButton():
matchList.append(abc)
return matchList
Use a MessageDialog. There are lots of examples on the web. Here are a couple:
And here's a really simple example:
import wx
########################################################################
class MainFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Test")
panel = wx.Panel(self)
btn = wx.Button(panel, label="Ask Question")
btn.Bind(wx.EVT_BUTTON, self.showMessageDlg)
#----------------------------------------------------------------------
def showMessageDlg(self, event):
"""
Show a message
"""
msg = "Do you want to continue?"
title = "Question!"
style = wx.YES_NO|wx.YES_DEFAULT|wx.ICON_QUESTION
dlg = wx.MessageDialog(parent=None, message=msg,
caption=title, style=style)
result = dlg.ShowModal()
if result == wx.ID_YES:
print "User pressed yes!"
else:
print "User pressed no!"
dlg.Destroy()
if __name__ == "__main__":
app = wx.App(False)
frame = MainFrame()
frame.Show()
app.MainLoop()
You would probably want to call your match list method if the user pressed the yes button rather than just printing a message to stdout though.