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

Varsha Purohit varsha.purohit at gmail.com
Sat Nov 17 21:44:41 CET 2007

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)


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

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

Any help is appreciated....

Varsha Purohit,
Graduate Student

More information about the Tutor mailing list