Newbie help on wxPython

Tim Roberts timr at
Tue Sep 4 08:10:54 CEST 2001

"jsnyder" <trelis at> wrote:
>def OnOpen(self,e):
>->    dlg=wxFileDialog(self, "Choose a file", self.dirname, "","*.*",
>        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.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.

Yes.  At the time of the wxFileDialog call, there is no member called
"dirname" in your object.  You're referring to a variable that does not

That parameter is supposed to supply the default directory name for
wxFileDialog to use.  If you have no default, leave it empty:

   dlg=wxFileDialog(self, "Choose a file", "", "","*.*", wxOPEN)
- Tim Roberts, timr at
  Providenza & Boekelheide, Inc.

More information about the Python-list mailing list