Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed python console output to wxPython

Is there a way I can embed the console window in to a wxPython form?

When I run my code, both the python console and wxPython Form open, but I would like to see the information on the App window somehow

like image 768
Hyperion Avatar asked Sep 10 '25 09:09

Hyperion


1 Answers

I found a way to redirect after some searching

class RedirectText(object):
    def __init__(self,aWxTextCtrl):
        self.out = aWxTextCtrl

    def write(self,string):
        self.out.WriteText(string)

Then I just setup a TextCtrl from wxPython to redirect the output to

self.log = wx.TextCtrl(main_panel, -1, size=(200, 100), style=wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
redir = RedirectText(self.log)
sys.stdout = redir
like image 160
Hyperion Avatar answered Sep 13 '25 05:09

Hyperion