Hi Alan, 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...
class ScrolledWindow(wx.Frame): 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) txt1.write(name) self.Centre() self.Show() 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() Fname = self.filename self.dirname=dlg.GetDirectory() #f=open(os.path.join(self.dirname, self.filename),'r') #self.control.SetValue(f.read()) # self.txt1.WriteText(Fname) f.close() dlg.Destroy() return Fname app = wx.App() ScrolledWindow(None, -1, 'Aliens') app.MainLoop() I donno the alternative to this now... :( On Nov 17, 2007 3:35 PM, Alan Gauld <[EMAIL PROTECTED]> wrote: > > "Varsha Purohit" <[EMAIL PROTECTED]> 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. > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- Varsha Purohit _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor