如何从框架中点击按钮获取值?
btnYes = wx.Button(panel, -1, "OK")
self.Bind(wx.EVT_BUTTON, self.clickYes, btnYes)
def clickYes(self, evt):
print "clicked Yes"
self.Close()
每当用户单击“是”时,我想获取一个值来检查其他模块。像确认标志的东西。当用户确认一件物品然后继续做其他物品。我将使用的确认标志如下:
def my_methodABC():
matchList = []
for x, y in product(d1rows, d2rows):
if userConfirmedFromWxPythonClickYesButton():
matchList.append(abc)
return matchList
答案 0 :(得分:0)
使用MessageDialog。网上有很多例子。这是一对夫妇:
这是一个非常简单的例子:
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()
如果用户按下“是”按钮而不是仅仅向stdout打印消息,则可能需要调用匹配列表方法。