Michele Alzetta wrote:
By the way, the examples in the 'Crash course' don't seem to work, at
least not wih wxpython 2.4 - here is the simplest:
---------------------------------------------------------------------------------------
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Hello My World")
self.Bind(wx.EVT_CLOSE, self.OnClose)
self.Show()
def OnClose(self, evt):
dlg = wx.MessageDialog(self, 'Are you sure you want to close My World?',
'Closing...', wx.YES_NO | wx.ICON_QUESTION)
ret = dlg.ShowModal()
dlg.Destroy()
if ret == wx.ID_YES:
evt.Skip()
app = wx.App(0)
MyFrame()
app.MainLoop()
-------------------------------------------------------------------------------------------
Fails with:
Traceback (most recent call last):
File "hello.py", line 18, in -toplevel-
app = wx.App(0)
File "/usr/lib/python2.3/site-packages/wxPython/wx.py", line 1951, in __init__
_wxStart(self.OnInit)
AttributeError: wxApp instance has no attribute 'OnInit'
wxPython 2.5.x is needed to use a bare wx.App (without deriving and adding an OnInit method) and also for the Bind(...) method. For 2.4 it would look something like this:
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "Hello My World")
wx.EVT_CLOSE(self, self.OnClose)
self.Show()
def OnClose(self, evt):
dlg = wx.MessageDialog(self, 'Are you sure you want to close My World?',
'Closing...', wx.YES_NO | wx.ICON_QUESTION)
ret = dlg.ShowModal()
dlg.Destroy()
if ret == wx.ID_YES:
evt.Skip()
app = wx.PySimpleApp(0)
MyFrame()
app.MainLoop()
···
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!