Simply replace your line:
app = wx.PySimpleApp()
with
app = wx.PySimpleApp(0) # (redirects the output of sys.stderr to the prompt)
You will discover, as I did, that you invoked the file “sample.txt” before you created it
···
2008/5/15 Terry Carroll carroll@tjc.com:
wxPython beginner here. I’m trying a very simple wxPython program, to do
nothing more than open a text window displaying text from a small file.
I see the window flash up, but the program terminates. My expectation was that
the window would stay open, and then when I hit the close button, my program
would terminate. Where am I going wrong?
the program:
import wx
class TextFrame(wx.Frame):
def __init__(self, filename): wx.Frame.__init__(self, None, -1, title=filename, style=wx.DEFAULT_FRAME_STYLE) panel = wx.Panel(self, -1) lines = file(filename).readlines() tc = wx.TextCtrl(panel, -1, style=wx.TE_MULTILINE) for line in lines: tc.AppendText(line)
if name == “main”:
filename = "sample.txt" app = wx.PySimpleApp() frame = TextFrame(filename) frame.Show() app.MainLoop
wxpython-users mailing list