Newbie help on wxPython

jsnyder trelis at mindspring.com
Mon Sep 3 18:08:55 EDT 2001


I'm working with the wxPython tutorial and have a problem with this code for
opening a file dialog:

def OnOpen(self,e):
->    dlg=wxFileDialog(self, "Choose a file", self.dirname, "","*.*",
wxOPEN)
        if dlg.ShowModal()==wxID_OK:
            self.filename=dlg.GetFilename()
            self.dirname =dlg.GetDirectory()
->         f=open(os.path.join(self.dirname,self.filename),'r')
            self.control.SetValue(f.read())
            f.close()
        dlg.Destroy()

In the call to wxFileDialog, using the self.dirname call from the os module
results in the error below, using the same call later in the open() works
just fine.

Traceback (most recent call last):
  File "C:\Python21\SampleEditor.pyw", line 46, in OnOpen
    dlg=wxFileDialog(self, "Choose a file", self.dirname, "","*.*", wxOPEN)
AttributeError: MainWindow instance has no attribute 'dirname'

Any ideas?  TIA.

Joe Snyder







More information about the Python-list mailing list