Corrected your code a little and it works just fine:
''' TextFileDisp00.py
'''
import wx
import codecs
#-------------------
class TextFrame(wx.Frame):
def __init__(self, parent, mytitle, mysize):
wx.Frame.__init__(self, parent, -1, mytitle, mysize)
self.menubar = wx.MenuBar()
self.file = wx.Menu()
self.SetMenuBar(self.menubar)
self.menubar.Append(self.file,'&File')
self.openitem = self.file.Append(wx.ID_ANY,'&Open')
self.Bind(wx.EVT_MENU,self.openevent,self.openitem)
self.runitem = self.file.Append(wx.ID_ANY,'&Run')
self.Bind(wx.EVT_MENU,self.runevent,self.runitem)
self.exititem = self.file.Append(wx.ID_ANY,'E&xit')
self.Bind(wx.EVT_MENU,self.exitevent,self.exititem)
self.background = wx.Panel(self)
self.background.SetBackgroundColour("white")
self.vbox = wx.BoxSizer(wx.VERTICAL)
self.vbox.Add(self.background, proportion=1, flag=wx.EXPAND) #!!!!
self.SetSizer(self.vbox)
self.fileisopen = False
self.Show()
def openevent(self, event):
filedialog = wx.FileDialog(self,
message = 'Open text file',
defaultDir = '.',
defaultFile = 'TestTOC.txt',
wildcard = 'Textfile (.txt .prn)|*.txt;*.prn|All (.*)|*.*', #!!!!
style = wx.OPEN)
if filedialog.ShowModal() == wx.ID_OK:
self.path = filedialog.GetPath()
self.fileisopen = True
def runevent(self, event):
if not self.fileisopen:
msgbox = wx.MessageDialog(self.background,
message="No file is open!", style=wx.OK)
if msgbox.ShowModal() == wx.ID_OK:
msgbox.Destroy()
else:
myOK = True
linenr = 0
InFile = codecs.open(self.path, 'r')
textline = InFile.readline()
while textline <> '' and myOK:
linenr += 1
msg = "Line " + repr(linenr) + ": " + textline
msgbox = wx.MessageDialog(self.background,
message=msg, style=wx.OK+wx.CANCEL)
if msgbox.ShowModal() == wx.ID_CANCEL:
myOK = False
msgbox.Destroy()
textline = InFile.readline()
msg = "Finished, # lines = " + repr(linenr)
msgbox = wx.MessageDialog(self.background,
message=msg, style=wx.OK)
if msgbox.ShowModal() == wx.ID_OK:
msgbox.Destroy()
InFile.close()
self.Destroy()
def exitevent(self, event):
self.Destroy()
#-------------------
''' Main application
'''
app = wx.App(redirect = False)
mywidth = 300
myheight = 150
mytitle = "Text file display"
frame = TextFrame(None, mytitle, (mywidth,myheight))
app.MainLoop() Line one of wx.AboutBox() has a larger font, maybe you can use that. See: http://www.daniweb.com/forums/post901743-112.html
sneekula
Nearly a Posting Maven
2,427 posts since Oct 2006
Reputation Points: 961
Solved Threads: 212