Hello, I am newish to wxPython and I am attmpting to make a text editor
Everytime it attempts the open file code it gets this error:
IOError: [Errno 22] invalid mode ('r') or filename: u''
WHY!!!
here is the code...

import wx
import os
wildcard = "Text file (*.txt)|*.txt;|"\
         "All files (*.*)|*.*"

class frame(wx.Frame):
    def __init__(self,parent,id):    
        wx.Frame.__init__(self,parent,id,'Simple Text Control!', size=(478,300))
        panel=wx.Panel(self)
        edit=wx.TextCtrl(panel,1,size=(300,220), pos=(2,2), style = wx.TE_MULTILINE)
        btn=wx.Button(panel, -1, "Open File", pos=(342,15), size=(95,32))
        self.Bind(wx.EVT_BUTTON, self.Open, btn)
    def Open(self, event):
        dlg = wx.FileDialog(
        self, message="Grab your file...",
        defaultFile="",
        wildcard=wildcard,
        style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR
        )
        self.dirname=dlg.GetDirectory()
        self.filename=dlg.GetFilename()
        if dlg.ShowModal() == wx.ID_OK:
            filehandle=open(os.path.join(self.dirname, self.filename),'ab')
            self.edit.SetValue(filehandle.read())
            filehandle.close()
            dlg.Destroy()

if __name__=='__main__':
    app=wx.PySimpleApp()
    frame=frame(parent=None,id=-1)
    frame.Show()
    app.MainLoop()

You are reading filename and dirname you show the dialog, those lines must be inside if block. 'ab' is strange mode to open file you only read. Also there is not defined variable 'self.edit'.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.