4

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

5
  • something like pycrust ? Commented Jan 9, 2019 at 19:28
  • Are you wanting to redirect stdout from things like print functions? Commented Jan 9, 2019 at 20:11
  • @Jean-FrançoisFabre I know it was abandoned years ago and comes with wxPython now, but the documentation is slim to none. Looking for something similar without all the extra Commented Jan 10, 2019 at 1:34
  • @MikeDriscoll Yes exactly, I would like what I print to console to show up on the wxPython App like in a text block or richtext, just a text window to output in general on the form without the console opening up with the app Commented Jan 10, 2019 at 1:36
  • I think it is better to have it outside, but for aesthetics - sure. What if your GUI has processes which already redirect the stdout? Wouldn't the answer not work? Commented Apr 2, 2021 at 14:43

1 Answer 1

4

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.