[Tutor] [wxPython-users] How to save file name of file opened fromwx.FileDialog ?
varsha.purohit at gmail.com
Sun Nov 18 03:09:51 CET 2007
I am actually calling the binding function and then writing it
into the text value... i tried using simple print in the openfile
function and it shows the filename. I am trying to return the file
name value but even that is not responding...
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(350, 300))
panel = wx.Panel(self, -1)
txt1 = wx.TextCtrl(panel, -1, pos=(30, 100), size=(150, 20))
button11 = wx.Button(panel, -1, "Open", pos=(200,100))
name = self.Bind(wx.EVT_BUTTON, self.OnOpen, button11)
self.dirname = ''
dlg = wx.FileDialog(self, "Choose a file", self.dirname,"",
Fname = self.filename
app = wx.App()
ScrolledWindow(None, -1, 'Aliens')
I donno the alternative to this now... :(
On Nov 17, 2007 3:35 PM, Alan Gauld <alan.gauld at btinternet.com> wrote:
> "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
> Alan G.
> Tutor maillist - Tutor at python.org
More information about the Tutor