Phil
unread,Jul 11, 2021, 1:00:50 AM7/11/21Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to wxpytho...@googlegroups.com
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