Start New Discussion within our Software Development Community

Hello Everyone,
In my application i need to select a file using open dialog
box. And then i dont need to open the file. I just need to display the
name of the selected file in a text control. And then open the file in
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.


import wx
import os

Fname = '' #Global variable to hold the file name.
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))
self.Bind(wx.EVT_BUTTON, self.OnOpen, button11)
txt1.write(Fname)

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()
dlg.Destroy()

app = wx.App()
ScrolledWindow(None, -1, 'Aliens')
app.MainLoop()


Any help is appreciated....

Rani

This is solved

import wx
import os

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)
self.txt1 = wx.TextCtrl(panel, -1, pos=(30, 100), size=(150, 20))
self.button11 = wx.Button(panel, -1, "Open", pos=(200,100))
self.button11.Bind(wx.EVT_BUTTON, self.OnOpen)
#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()
self.dirname=dlg.GetDirectory()

self.txt1.write(self.filename)
dlg.Destroy()


app = wx.App()
ScrolledWindow(None, -1, 'Aliens')
app.MainLoop()

This question has already been answered. Start a new discussion instead.