Skip to content

Instantly share code, notes, and snippets.

@driscollis
Created September 5, 2014 21:03
Show Gist options
  • Save driscollis/2da409123d1859ad7301 to your computer and use it in GitHub Desktop.
Save driscollis/2da409123d1859ad7301 to your computer and use it in GitHub Desktop.
wxPython redirect text to file
import wx
import sys
########################################################################
class redirect(object):
""""""
#----------------------------------------------------------------------
def __init__(self, obj):
"""Constructor"""
self.filename = open("frame.log", "w")
#----------------------------------------------------------------------
def write(self, text):
""""""
if self.filename.closed:
pass
else:
self.filename.write(text)
self.filename.flush()
########################################################################
class MyFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Redirect")
sys.stdout = redirect(self)
btn = wx.Button(self, label="Test")
btn.Bind(wx.EVT_BUTTON, self.onButton)
print "App started"
#----------------------------------------------------------------------
def onButton(self, event):
""""""
print "You pressed a button!"
if __name__ == "__main__":
app = wx.App(False)
frame = MyFrame()
frame.Show()
app.MainLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment