[Tutor] [wxPython-users] How to save file name of file opened fromwx.FileDialog ?

Alan Gauld alan.gauld at btinternet.com
Sun Nov 18 00:35:51 CET 2007


"Varsha Purohit" <varsha.purohit at gmail.com> wrote

> later part of the program.  But i am not able to get the file name 
> and
> display it in the text control. Here is the sample code.
>
> Fname = '' #Global variable to hold the file name.

You don't need this since its stored in self.filename.

> class ScrolledWindow(wx.Frame):
>    def __init__(self, parent, id, title):
>        txt1 = wx.TextCtrl(panel, -1, pos=(30, 100), size=(150, 20))

If you want to write to it you need to store it in the object so this
should be self.txt1

>        txt1.write(Fname)

You can't write the filename yet as it hasn't been fetched

>
>    def OnOpen(self,event):
>        self.dirname = ''
>        dlg = wx.FileDialog(self, "Choose a file", self.dirname,"",
> "*.*", wx.OPEN)
>        if dlg.ShowModal()==wx.ID_OK:
>            self.filename=dlg.GetFilename()

Here you get the filename but don't write it to the text control

HTH,

Alan G. 




More information about the Tutor mailing list