這使我指出了正確的方向。以下是現在可用的代碼。
感謝
class Frame(wx.Frame):
def __init__(self, title):
wx.Frame.__init__(self, None, title=title, pos=(150,150), size=(400,300))
self.Bind(wx.EVT_CLOSE, self.OnClose)
menuBar = wx.MenuBar()
menu = wx.Menu()
m_exit = menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Close window and exit program.")
self.Bind(wx.EVT_MENU, self.OnClose)
self.Bind(wx.EVT_MENU, self.OnClose, m_exit)
menuBar.Append(menu, "&File")
menu = wx.Menu()
m_about = menu.Append(wx.ID_ABOUT, "&About", "Information about this program")
self.Bind(wx.EVT_MENU, self.OnAbout, m_about)
menuBar.Append(menu, "&Help")
self.SetMenuBar(menuBar)
self.statusbar = self.CreateStatusBar()
panel = wx.Panel(self)
box = wx.GridSizer(2, 2)
m_new_audit = wx.Button(panel, wx.NewId(), "New Audit.")
m_new_audit.Bind(wx.EVT_BUTTON, self.NewAudit)
m_view_audit = wx.Button(panel, wx.NewId(), "View Previous Audits.")
m_view_audit.Bind(wx.EVT_BUTTON, self.ViewAudit)
m_add_engineer = wx.Button(panel, wx.NewId(), "Add New Engineer.")
m_add_engineer.Bind(wx.EVT_BUTTON, self.AddEngineer)
m_close = wx.Button(panel, wx.NewId(), "Close.")
m_close.Bind(wx.EVT_BUTTON, self.OnClose)
box.Add(m_new_audit, 10, wx.EXPAND, 10)
box.Add(m_view_audit, 10, wx.EXPAND, 10)
box.Add(m_add_engineer, 10, wx.EXPAND, 10)
box.Add(m_close, 10, wx.EXPAND, 10)
panel.SetSizer(box)
panel.Layout()
def OnClose(self, event):
dlg = wx.MessageDialog(self,
"Do you really want to close this application?",
"Confirm Exit", wx.OK|wx.CANCEL|wx.ICON_QUESTION)
result = dlg.ShowModal()
dlg.Destroy()
if result == wx.ID_OK:
self.Destroy()
def NewAudit(self, event):
dlg = wx.MessageDialog(self,
"Create New Audit?",
"Confirm?", wx.OK|wx.CANCEL|wx.ICON_QUESTION)
result = dlg.ShowModal()
if result == wx.ID_OK:
event = "New Audit"
print event
dlg.Destroy()
def ViewAudit(self, event):
dlg = wx.MessageDialog(self,
"View Previous Audit?",
"Confirm?", wx.OK|wx.CANCEL|wx.ICON_QUESTION)
result = dlg.ShowModal()
if result == wx.ID_OK:
event = "Previous Audit"
print event
dlg.Destroy()
def AddEngineer(self, event):
dlg = wx.MessageDialog(self,
"Add New Engineer?",
"Confirm?", wx.OK|wx.CANCEL|wx.ICON_QUESTION)
result = dlg.ShowModal()
if result == wx.ID_OK:
event = "New Engineer"
print event
dlg.Destroy()
def OnAbout(self, event):
dlg = AboutBox()
dlg.ShowModal()
dlg.Destroy()