wxpython: Redirect the stdout to a textctrl

Alejandro alejandro.weinstein at gmail.com
Tue Jun 19 16:16:47 EDT 2007


Hi:

I want to redirect stdout to a textctrl I have. From what I read in
the wxpython documentation, I can use the wxLogTextCtrl class to do
this. I am doing the following:

class MyGui(gui.MyFrame):  #gui.MyFrame generated by wxGlade
    def __init__(self, *args, **kwds):
        gui.MyFrame.__init__(self, *args, **kwds)
        # ... code removed ...
        wx.Log_SetActiveTarget(wx.LogTextCtrl(self.text_ctrl_2))
        print 'foo' #to test the redirection

if __name__ == "__main__":
    app = wx.App(redirect=wx.LogTextCtrl)
    wx.InitAllImageHandlers()
    gui = MyGui(None, -1, "")
    app.SetTopWindow(gui)
    gui.Show()
    app.MainLoop()

However, the output instead of going to my textctrl, goes to a new
window named "xwPython: stdout/stderr".

What am I missing?




More information about the Python-list mailing list