Created
September 5, 2014 21:03
-
-
Save driscollis/2da409123d1859ad7301 to your computer and use it in GitHub Desktop.
wxPython redirect text to file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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