Print redirection problem
Phil <[email protected]> Sun, 11 Jul 2021 15:00:40 +1000
| Newsgroups | gmane.comp.python.wxpython |
|---|---|
| Message-ID | <[email protected]> |
Thank you for reading this.
I'm continuing to have trouble reconciling programming styles that I see
in books with examples that I see online. In an effort to overcome this
problem I have a template that seems to work in most instances yet I
have come unstuck with an example on page 35 from "WxPython in Action
2012" that shows how redirect the output of print statements to the
console or a file.
Print from MyApp is displayed but nothing after that.
import wx
class MyApp(wx.App):
def __init__(self, redirect=True, filename=None):
print('App __init__') # This is printed to the console
super().__init__(self, redirect, filename)
# init frame
self.InitFrame()
def InitFrame(self):
print('Init Frame')
frame = MyFrame(parent=None,
title="Redirection",
size=(300, 300),
pos=(100, 100))
frame.Show()
class MyFrame(wx.Frame):
def __init__(self, parent, title, size, pos):
print('Frame __init__')
super().__init__(parent=parent, title=title, size=(300, 300),
pos=pos)
self.OnInit()
def OnInit(self):
panel = MyPanel(parent=self)
class MyPanel(wx.Panel):
def __init__(self, parent):
super().__init__(parent=parent)
wx.StaticText(self, label="Redirect print to panel or file",
pos=(20, 20))
if __name__ == "__main__":
app = MyApp(redirect=True)#, 'filename')
app.MainLoop()
The error message is:
App __init__
Traceback (most recent call last):
File "/usr/lib/python3.8/idlelib/run.py", line 559, in runcode
exec(code, self.locals)
File "/home/phil/Python/wx_redirection.py", line 37, in <module>
app = MyApp(redirect=True)#, 'filename')
File "/home/phil/Python/wx_redirection.py", line 6, in __init__
super().__init__(self, redirect, filename)
File "/home/phil/.local/lib/python3.8/site-packages/wx/core.py", line
2175, in __init__
self.SetUseBestVisual(useBestVisual)
TypeError: PyApp.SetUseBestVisual(): argument 1 has unexpected type
'NoneType'
It would seem that the error is due to something in MyFrame not being
setup correctly but at the moment I cannot see how to solve the problem.
--
Regards,
Phil
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/b7d5a34f-e7b4-ebf5-31d8-4f9fb58cec16%40gmail.com.