tags:

views:

47

answers:

2
#!/usr/bin/python

import wx
import os
import sys

class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(480, 400))
        self.panel = MyPanel(self, -1)
        self.Centre()
        self.Show(True)
        setstd()
        print 'test'
        """
        syncall()
        """

class MyPanel(wx.Panel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)
        self.text = wx.StaticText(self, -1, '', (40, 60))

class MyText():
    def write(string):
        label = frame.panel.text.GetLabel()
        frame.panel.text.SetLabel(string)

def setstd():
    sys.stdout = MyText()
    sys.stderr = MyText()

app = wx.App()
frame = MyFrame(None, -1, 'DropBox log')
app.MainLoop()

Without print 'test', it even runs, but with print 'test', it doesn't run nor redirect output.

How to redirect standard output to print messages in gui instead of terminal?

+2  A: 

When you use the print statement with wxPython, where it ends up depends on how you called wx.App().

wx.App(redirect=False) or simply wx.App(0) will send print statements to a console window, otherwise they will be sent to a little textbox window.

Nick T