Textctrl problems

In the following code, I have created a panel with a button and a textctrl
object on it. I have also created a menubar that will create a new text file
(i.e. textctrl object). My problem is that when I create a new file, it
displays the textctrl over the top left of my existing panel. How do I get the
new file to display in the textctrl on my panel? I am having the save problems
when trying to open a text file. It simply displays the new textctrl over the
top left of my panel. However, I think that if I see an example or two, I could
figure both problems out as they are probably related.

#!/usr/bin/env python

import wx
import os

class MyGUI(wx.App):
    def OnInit(self):
        self.frame = Frame(None, title = "MyGUI", size = (600, 480))
        self.frame.CenterOnScreen()
        self.frame.Show()
        self.SetTopWindow(self.frame)
        return True

class Frame(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)
        self.panel = CreateMainPanel(self)
        filemenu = wx.Menu()
  filemenu.Append(wx.ID_NEW, "&New")
  menubar = wx.MenuBar()
  menubar.Append(filemenu, "&File")
  self.SetMenuBar(menubar)
  
  wx.EVT_MENU(self, wx.ID_NEW, self.onNew)

    def onNew(self, event):
    
        """
  Event handler for creating a new file
  """
  
        self.editor = wx.TextCtrl(self, wx.ID_ANY, size = (400, 250),
                style = wx.TE_MULTILINE)
        self.SetTitle("New file -- Unsaved")

class CreateMainPanel(wx.Panel):

    """
    Creates new panel with a button and textctrl widget on it
    """
    
    def __init__(self, *args):
        wx.Panel.__init__(self, *args)
  
  self.container1 = wx.BoxSizer(wx.VERTICAL)
  self.container1.Add((0,50), 0, 0)
  self.container1.Add(wx.Button(self, wx.ID_ANY, "Do Something"))
  self.container1.Add((0,50), 0, 0)
  
  self.container2 = wx.GridBagSizer(hgap = 5, vgap = 5)
  self.container2.Add(self.container1, pos = (0, 0))
  self.container2.Add(wx.TextCtrl(self, wx.ID_ANY, style = wx.TE_MULTILINE),
                                  span = (3, 2), pos = (0, 1),
          flag = wx.EXPAND | wx.ALL, border = 15)
  self.container2.AddGrowableCol(1)
  self.container2.AddGrowableRow(2)
  self.SetSizer(self.container2)

def main():
    app = MyGUI()
    app.MainLoop()

if __name__ == "__main__":

    main()

self.editor = wx.TextCtrl(self, wx.ID_ANY, size = (400, 250),

                              style = wx.TE_MULTILINE)

I guess the problem here is that when you make this textCtrl, you don’t
tell where it should be put. It’s parent is given as self, and in that case it

means the whole Frame. It is not assigned to a sizer or anything, so it
is just put at the 0,0 position of the Frame.

Maybe what would be better is just to create a textCtrl one time, and
then when you want to load a file, set the contents of that textCtrl to

the contents of the file with textCtrl.SetValue().

Also, is there a reason to be using three separate classes? I’ve been
getting by with one class, the Frame itself, and that’s worked for me.
Below is a small sample that does what you want. Make a text file

called tester.txt on your desktop and change the user part of the file
path to match your path and it should work. I’ve just used one
horizontal box sizer for this.

HTH

···

On 9/23/07, Regan Tackett regantackett@comcast.net wrote:

In the following code, I have created a panel with a button and a textctrl
object on it. I have also created a menubar that will create a new text file
(i.e. textctrl object). My problem is that when I create a new file, it

displays the textctrl over the top left of my existing panel. How do I get the
new file to display in the textctrl on my panel? I am having the save problems
when trying to open a text file. It simply displays the new textctrl over the

top left of my panel. However, I think that if I see an example or two, I could
figure both problems out as they are probably related.


import wx

def create(parent):
return Frame1(parent)

class Frame1(wx.Frame):
def init(self, parent):

    wx.Frame.__init__(self, id=-1, name='', parent=parent,

          pos=wx.Point(349, 156), size=wx.Size(403, 489),
          style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
    self.SetClientSize(wx.Size(395, 455))

    self.panel1 = wx.Panel(id=-1, name='panel1', parent=self,

          pos=wx.Point(0, 0), size=wx.Size(395, 455),
          style=wx.TAB_TRAVERSAL)

    self.button1 = wx.Button(id=-1, label='button1',
          name='button1', parent=

self.panel1, pos=wx.Point(15, 15),
size=wx.Size(75, 23), style=0)

    self.textCtrl1 = wx.TextCtrl(id=-1, name='textCtrl1',
          parent=self.panel1, pos=wx.Point(120, 15), size=

wx.Size(260, 425),
style=0, value=‘textCtrl1’)

#This is your original file menu code untouched
    filemenu = wx.Menu()
    filemenu.Append(wx.ID_NEW, "&New")

    menubar = wx.MenuBar()
    menubar.Append(filemenu, "&File")
    self.SetMenuBar(menubar)

    wx.EVT_MENU(self, wx.ID_NEW, self.onNew)

#The sizer and its contents

    self.boxSizer1 = wx.BoxSizer(orient=wx.HORIZONTAL)
    self.boxSizer1.AddWindow(self.button1, 0, border=15, flag=wx.ALL)
    self.boxSizer1.AddWindow(self.textCtrl1, 1, border=15, flag=wx.ALL | wx.EXPAND

)
self.panel1.SetSizer(self.boxSizer1)

def onNew(self, event):
   #change the path here to match the path to YOUR desktop
    file = open('C:/Documents and Settings/user/Desktop/tester.txt', 'r')

    contents = file.read()
    self.textCtrl1.SetValue(contents)

if name == ‘main’:
app = wx.PySimpleApp()
frame = create(None)
frame.Show()

app.MainLoop

()

C M <cmpython <at> gmail.com> writes:

In the following code, I have created a panel with a button and a

textctrlobject on it. I have also created a menubar that will create a new text
file(i.e. textctrl object). My problem is that when I create a new file, it

displays the textctrl over the top left of my existing panel. How do I get

thenew file to display in the textctrl on my panel? I am having the save
problemswhen trying to open a text file. It simply displays the new textctrl
over the

top left of my panel. However, I think that if I see an example or two, I

couldfigure both problems out as they are probably related.

self.editor = wx.TextCtrl(self, wx.ID_ANY, size = (400, 250),
                                  style = wx.TE_MULTILINE)I guess the problem

here is that when you make this textCtrl, you don'ttell where it should be put.
It's parent is given as self, and in that case it

means the whole Frame. It is not assigned to a sizer or anything, so itis

just put at the 0,0 position of the Frame.Maybe what would be better is just to
create a textCtrl one time, andthen when you want to load a file, set the
contents of that textCtrl to

the contents of the file with textCtrl.SetValue(). Also, is there a reason to

be using three separate classes? I've beengetting by with one class, the Frame
itself, and that's worked for me.Below is a small sample that does what you
want. Make a text file

called tester.txt on your desktop and change the user part of the filepath to

match your path and it should work. I've just used one horizontal box sizer for
this.HTH----------------------------

import wxdef create(parent): return Frame1(parent)class

Frame1(wx.Frame): def __init__(self, parent): wx.Frame.__init__(self,
id=-1, name='', parent=parent,

              pos=wx.Point(349, 156), size=wx.Size(403, 489),

style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
self.SetClientSize(wx.Size(395, 455)) self.panel1 = wx.Panel(id=-1,
name='panel1', parent=self,

              pos=wx.Point(0, 0), size=wx.Size(395, 455),

style=wx.TAB_TRAVERSAL) self.button1 = wx.Button(id=-1,
label='button1', name='button1', parent=

self.panel1, pos=wx.Point(15, 15), size=wx.Size(75, 23),

style=0) self.textCtrl1 = wx.TextCtrl(id=-1,
name='textCtrl1', parent=self.panel1, pos=wx.Point(120, 15), size=

wx.Size(260, 425), style=0, value='textCtrl1') #This is your

original file menu code untouched filemenu = wx.Menu()
filemenu.Append(wx.ID_NEW, "&New")

        menubar = wx.MenuBar() menubar.Append(filemenu, "&File")

self.SetMenuBar(menubar) wx.EVT_MENU(self, wx.ID_NEW, self.onNew) #The
sizer and its contents

        self.boxSizer1 = wx.BoxSizer(orient=wx.HORIZONTAL)

self.boxSizer1.AddWindow(self.button1, 0, border=15, flag=wx.ALL)
self.boxSizer1.AddWindow(self.textCtrl1, 1, border=15, flag=wx.ALL | wx.EXPAND

) self.panel1.SetSizer(self.boxSizer1) def onNew(self,

event): #change the path here to match the path to YOUR desktop
file = open('C:/Documents and Settings/user/Desktop/tester.txt', 'r')

        contents = file.read() self.textCtrl1.SetValue(contents)if

__name__ == '__main__': app = wx.PySimpleApp() frame = create(None)
frame.Show() app.MainLoop

()

Thanks for your help. I understand everything that you showed me, and it worked
great. However, I would like to build a multi-panel application and therefore,
would like to put each of my panels in separate classes. I know that there is
an easy solution to my problem, but I've just started learning GUI programming
with wxPython and can't figure it out. Do you have any other suggestions?

···

On 9/23/07, Regan Tackett <regantackett <at> comcast.net> wrote:

Thanks for your help. I understand everything that you showed me, and it worked
great. However, I would like to build a multi-panel application and therefore,
would like to put each of my panels in separate classes. I know that there is
an easy solution to my problem, but I've just started learning GUI programming
with wxPython and can't figure it out. Do you have any other suggestions?

Maybe you should use Notebook control to contain your multiple TextCtrl.

···

--
I like python!
UliPad <<The Python Editor>>: Google Code Archive - Long-term storage for Google Code Project Hosting.
My Blog: http://www.donews.net/limodou

Thanks for your help. I understand everything that you showed me, and it worked

great. However, I would like to build a multi-panel application and therefore,
would like to put each of my panels in separate classes. I know that there is
an easy solution to my problem, but I’ve just started learning GUI programming

with wxPython and can’t figure it out. Do you have any other suggestions?

Going along with limodou’s suggestion, wxNotebook or really any of the
“book” controls are one nice way to display multiple panels (but not all at

the same time). If you haven’t already you should take a look at the demo.
Put “book” in the search bar at the bottom and then you can have a look
at them. And you don’t have to have panels in separate classes.

If that’s not the way to go, let us know. It’s hard to picture just what you
want from the limited description.

CM

Going along with limodou's suggestion, wxNotebook or really any of the"book"

controls are one nice way to display multiple panels (but not all at

the same time). If you haven't already you should take a look at the demo.Put

"book" in the search bar at the bottom and then you can have a lookat them. And
you don't have to have panels in separate classes.

If that's not the way to go, let us know. It's hard to picture just what

youwant from the limited description.CM

Thanks for the suggestions. My question was asked because of what I read on
the wiki style guide.

http://wiki.wxpython.org/wxPython_Style_Guide

In it, they state that you should create separate panel classes instead of
nesting panels in one class. The code that I supplied to start this thread
didn't have nested panels, but I was nonetheless wondering (if you had a gui
app with s separate panel class housing a textctrl) how you would update that
specific panel's textctrl widget if you wanted to load text into it or create
a new textctrl from the menubar's file menu. Certainly on larger
applications that don't use "book" controls such as Notebooks, this must be
an issue. Does anyone have any knowledge about how one could accomplish
this, or is "book" controls how it's done?

I'v seen your souce code, and when call New menu, you'll create a new
TextCtrl at all. And I think open file and read content from it, then
put it to a textctrl maybe you want. But you don't need to create a
new TextCtrl at all, just reuse the same TextCtrl. And you considered
multiple TextCtrl, so I want to know:

Will these TextCtrl be placed one panel or different panel. For
different panel, you can use "book-like" control, such as Notebook to
hold them. If you want to put multiple TextCtrl in *ONE* panel, you
may need to use wx.Sizer to do such thing. And you can read details
about wx.Sizer document, here's the clue about how to add a new
TextCtrl dynamically:

1. Create a new textctrl with parent paramter is panel object, but
when you created it, the textctrl maybe not arranged as you wish.
2. Add it to a sizer, for example wxBoxSizer(style=wx.VERTICAL)
3. Invoke Layout() method of the wxBoxSizer, and Layout() will
rearrange all widgets in the sizer object.

Maybe this will help you.

···

On 9/24/07, Regan Tackett <regantackett@comcast.net> wrote:

> Going along with limodou's suggestion, wxNotebook or really any of the"book"
controls are one nice way to display multiple panels (but not all at
> the same time). If you haven't already you should take a look at the demo.Put
"book" in the search bar at the bottom and then you can have a lookat them. And
you don't have to have panels in separate classes.
> If that's not the way to go, let us know. It's hard to picture just what
youwant from the limited description.CM
>
>
>
>

Thanks for the suggestions. My question was asked because of what I read on
the wiki style guide.

http://wiki.wxpython.org/wxPython_Style_Guide

In it, they state that you should create separate panel classes instead of
nesting panels in one class. The code that I supplied to start this thread
didn't have nested panels, but I was nonetheless wondering (if you had a gui
app with s separate panel class housing a textctrl) how you would update that
specific panel's textctrl widget if you wanted to load text into it or create
a new textctrl from the menubar's file menu. Certainly on larger
applications that don't use "book" controls such as Notebooks, this must be
an issue. Does anyone have any knowledge about how one could accomplish
this, or is "book" controls how it's done?

--
I like python!
UliPad <<The Python Editor>>: Google Code Archive - Long-term storage for Google Code Project Hosting.
My Blog: http://www.donews.net/limodou

Thanks for the suggestions. My question was asked because of what I read on
the wiki style guide.

http://wiki.wxpython.org/wxPython_Style_Guide

In it, they state that you should create separate panel classes instead of
nesting panels in one class. The code that I supplied to start this thread

didn’t have nested panels, but I was nonetheless wondering (if you had a gui
app with s separate panel class housing a textctrl) how you would update that
specific panel’s textctrl widget if you wanted to load text into it or create

a new textctrl from the menubar’s file menu. Certainly on larger
applications that don’t use “book” controls such as Notebooks, this must be
an issue. Does anyone have any knowledge about how one could accomplish

this, or is “book” controls how it’s done?

I’ve been probably ignoring that part from the style guide at my peril! Thanks
for pointing it out. I’ve included the code from before but now it does what you

are asking for: it uses a class for a separate panel, and allows you to write to
THAT textctrl on that panel. To go along with the point of the style guide I
threw a textctrl and a button on there and gave it a different background color

to make it stand out.

One thing: I have this issue that I’m confused about too, which is when you
run this frame it will look wrong but then if you resize it by dragging the edge,
even just a bit, it will lay out everything fine. Then try the menu (again, you

first have to change the path to match your desktop same as before) and it
will put whatever’s in your text file to the textctrl on the right hand panel.

Does anyone know why it doesn’t lay out right in the first place? I’ve
encountered this before when using sizers. .Update() or .Refresh()
doesn’t help, nor does .Layout() of the sizer or the whole frame. Anyone
have an idea?

Anyway, this should give the general idea. The annotations of the code

should also help I hope.

HTH,
CM

···

import wx

def create(parent):
return Frame1(parent)

#This class is what will be used from within the main frame.

#The instance of this class will be called “classedpanel” as
#you’ll see below…
class Panel1(wx.Panel):
def init(self, parent, id, pos, size, style, name):
wx.Panel.init(self, id=-1, name=‘’, parent=parent,

          pos=wx.Point(172, 237), size=wx.Size(239, 214),
          style=wx.TAB_TRAVERSAL)
    self.SetClientSize(wx.Size(231, 180))
    self.SetBackgroundColour(wx.Colour(134,23,54))

    self.textCtrl1 = wx.TextCtrl(id=-1, name='textCtrl1',
          parent=self, pos=wx.Point(40, 56), size=wx.Size(144, 80), style=0,
          value='textCtrl1')

     self.button1

= wx.Button(id=-1, label=‘another button’,
name=‘button1’, parent=self, pos=wx.Point(40, 24),
size=wx.Size(95, 23), style=0)

class Frame1(wx.Frame):
def init(self, parent):

    wx.Frame.__init__(self, id=-1, name='', parent=parent,
          pos=wx.Point(349, 156), size=wx.Size(900, 900),
          style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
    #self.SetClientSize(

wx.Size(900, 900))

    self.panel1 = wx.Panel(id=-1, name='panel1', parent=self,
          pos=wx.Point(0, 0), size=wx.Size(395, 455),
          style=wx.TAB_TRAVERSAL)

     self.button1

= wx.Button(id=-1, label=‘button1’,
name=‘button1’, parent=self.panel1, pos=wx.Point(15, 15),
size=wx.Size(75, 23), style=0)

    self.textCtrl1 = wx.TextCtrl(id=-1, name='textCtrl1',

          parent=self.panel1, pos=wx.Point(120, 15), size=wx.Size(260, 425),
          style=0, value='textCtrl1')

#This is now where the main frame makes an instance of the Panel1 class and

#calls it classedpanel. By writing it as self.classedpanel you make it available
#to all the functions in this Frame, which is handy, as you will need to call it in
#the function onNew.
self.classedpanel
= Panel1(self.panel1, id=-1, pos=(0,0), size=(100,200), style=None, name=‘mypanel’)

#This is your original file menu code
    filemenu = wx.Menu()
    filemenu.Append(wx.ID_NEW

, “&New”)
menubar = wx.MenuBar()
menubar.Append(filemenu, “&File”)
self.SetMenuBar(menubar)

    wx.EVT_MENU(self, wx.ID_NEW, self.onNew)

#The sizer and its contents

    self.boxSizer1 = wx.BoxSizer(orient=wx.HORIZONTAL)
    self.boxSizer1.AddWindow(self.button1, 0, border=15, flag=wx.ALL)
    self.boxSizer1.AddWindow(self.textCtrl1, 1, border=15, flag=wx.ALL | wx.EXPAND

)
self.boxSizer1.AddWindow(self.classedpanel, 1, border=15, flag=wx.ALL | wx. EXPAND)
self.panel1.SetSizer(self.boxSizer1)
self.boxSizer1.Layout()

def onNew(self, event):

    file = open('C:/Documents and Settings/user/Desktop/tester.txt', 'r')
    contents = file.read()
    self.classedpanel.textCtrl1.SetValue(contents)

if name == ‘main’:

app = wx.PySimpleApp()
frame = create(None)
frame.Show()

app.MainLoop()

I've been probably ignoring that part from the style guide at my peril!

Thanksfor pointing it out. I've included the code from before but now it does
what you

are asking for: it uses a class for a separate panel, and allows you to write

toTHAT textctrl on that panel. To go along with the point of the style guide I
threw a textctrl and a button on there and gave it a different background color

to make it stand out.One thing: I have this issue that I'm confused about

too, which is when yourun this frame it will look wrong but then if you resize
it by dragging the edge,even just a bit, it will lay out everything fine. Then
try the menu (again, you

first have to change the path to match your desktop same as before) and itwill

put whatever's in your text file to the textctrl on the right hand panel.Does
anyone know why it doesn't lay out right in the first place? I've

encountered this before when using sizers. .Update() or .Refresh()doesn't

help, nor does .Layout() of the sizer or the whole frame. Anyonehave an
idea?Anyway, this should give the general idea. The annotations of the code

should also help I hope.HTH,CM --------------------import wxdef

create(parent): return Frame1(parent)#This class is what will be used from
within the main frame.

#The instance of this class will be called "classedpanel" as #you'll see

below...class Panel1(wx.Panel): def __init__(self, parent, id, pos, size,
style, name): wx.Panel.__init__(self, id=-1, name='', parent=parent,

              pos=wx.Point(172, 237), size=wx.Size(239, 214),

style=wx.TAB_TRAVERSAL) self.SetClientSize(wx.Size(231, 180))
self.SetBackgroundColour(wx.Colour(134,23,54))

        self.textCtrl1 = wx.TextCtrl(id=-1, name='textCtrl1',

parent=self, pos=wx.Point(40, 56), size=wx.Size(144, 80), style=0,
value='textCtrl1') self.button1

= wx.Button(id=-1, label='another button', name='button1',

parent=self, pos=wx.Point(40, 24), size=wx.Size(95, 23),
style=0)class Frame1(wx.Frame): def __init__(self, parent):

        wx.Frame.__init__(self, id=-1, name='', parent=parent,

pos=wx.Point(349, 156), size=wx.Size(900, 900),
style=wx.DEFAULT_FRAME_STYLE, title='Frame1') #self.SetClientSize(

wx.Size(900, 900)) self.panel1 = wx.Panel(id=-1, name='panel1',

parent=self, pos=wx.Point(0, 0), size=wx.Size(395,
455), style=wx.TAB_TRAVERSAL) self.button1

= wx.Button(id=-1, label='button1', name='button1',

parent=self.panel1, pos=wx.Point(15, 15), size=wx.Size(75, 23),
style=0) self.textCtrl1 = wx.TextCtrl(id=-1, name='textCtrl1',

              parent=self.panel1, pos=wx.Point(120, 15), size=wx.Size(260,

425), style=0, value='textCtrl1')#This is now where the main frame
makes an instance of the Panel1 class and

#calls it classedpanel. By writing it as self.classedpanel you make it

available#to all the functions in this Frame, which is handy, as you will need
to call it in#the function onNew. self.classedpanel

= Panel1(self.panel1, id=-1, pos=(0,0), size=(100,200), style=None,

name='mypanel') #This is your original file menu code filemenu
= wx.Menu() filemenu.Append(wx.ID_NEW

, "&New") menubar = wx.MenuBar() menubar.Append(filemenu,

"&File") self.SetMenuBar(menubar) wx.EVT_MENU(self, wx.ID_NEW,
self.onNew) #The sizer and its contents

        self.boxSizer1 = wx.BoxSizer(orient=wx.HORIZONTAL)

self.boxSizer1.AddWindow(self.button1, 0, border=15, flag=wx.ALL)
self.boxSizer1.AddWindow(self.textCtrl1, 1, border=15, flag=wx.ALL | wx.EXPAND

) self.boxSizer1.AddWindow(self.classedpanel, 1, border=15, flag=wx.ALL
wx. EXPAND) self.panel1.SetSizer(self.boxSizer1)

self.boxSizer1.Layout() def onNew(self, event):

        file = open('C:/Documents and Settings/user/Desktop/tester.txt',

'r') contents = file.read()
self.classedpanel.textCtrl1.SetValue(contents)if __name__ == '__main__':

    app = wx.PySimpleApp() frame = create(None) frame.Show()

app.MainLoop()

Thanks for the help. I am running into the same problems as you. I can't get
it to layout correctly either. Does anyone know how to fix this problem?

Hi,

One thing: I have this issue that I'm confused about too,
which is when you run this frame it will look wrong but then
if you resize it by dragging the edge, even just a bit, it
will lay out everything fine. Then try the menu (again, you
first have to change the path to match your desktop same as
before) and it will put whatever's in your text file to the
textctrl on the right hand panel.

I got the Layout() call to work, but you need to call it when you're done
creating everything else. Delete the line "self.boxSizer1.Layout()" and
replace it with either of these (but not both):

self.panel1.Layout()

Or

self.SetClientSize(self.panel1.GetBestSize())

Worked for me on Windows XP, wxPython 2.8.4.2

~Mike~

···

import wx

def create(parent):
    return Frame1(parent)

#This class is what will be used from within the main frame.
#The instance of this class will be called "classedpanel" as
#you'll see below...
class Panel1(wx.Panel):
    def __init__(self, parent, id, pos, size, style, name):
        wx.Panel.__init__(self, id=-1, name='', parent=parent,
              pos=wx.Point(172, 237), size=wx.Size(239, 214),
              style=wx.TAB_TRAVERSAL)
        self.SetClientSize(wx.Size(231, 180))
        self.SetBackgroundColour(wx.Colour(134,23,54))

        self.textCtrl1 = wx.TextCtrl(id=-1, name='textCtrl1',
              parent=self, pos=wx.Point(40, 56),
size=wx.Size(144, 80), style=0,
              value='textCtrl1')

        self.button1 = wx.Button(id=-1, label='another button',
              name='button1', parent=self, pos=wx.Point(40, 24),
              size=wx.Size(95, 23), style=0)

class Frame1(wx.Frame):
    def __init__(self, parent):

        wx.Frame.__init__(self, id=-1, name='', parent=parent,
              pos=wx.Point(349, 156), size=wx.Size(900, 900),
              style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
        #self.SetClientSize( wx.Size(900, 900))

        self.panel1 = wx.Panel(id=-1, name='panel1', parent=self,
              pos=wx.Point(0, 0), size=wx.Size(395, 455),
              style=wx.TAB_TRAVERSAL)

        self.button1 = wx.Button(id=-1, label='button1',
              name='button1', parent=self.panel1,
pos=wx.Point(15, 15),
              size=wx.Size(75, 23), style=0)

        self.textCtrl1 = wx.TextCtrl(id=-1, name='textCtrl1',
              parent=self.panel1, pos=wx.Point(120, 15),
size=wx.Size(260, 425),
              style=0, value='textCtrl1')

#This is now where the main frame makes an instance of the
Panel1 class and #calls it classedpanel. By writing it as
self.classedpanel you make it available #to all the functions
in this Frame, which is handy, as you will need to call it in
#the function onNew.
        self.classedpanel = Panel1(self.panel1, id=-1,
pos=(0,0), size=(100,200), style=None, name='mypanel')
        
    #This is your original file menu code
        filemenu = wx.Menu()
        filemenu.Append(wx.ID_NEW , "&New")
        menubar = wx.MenuBar()
        menubar.Append(filemenu, "&File")
        self.SetMenuBar(menubar)

        wx.EVT_MENU(self, wx.ID_NEW, self.onNew)

    #The sizer and its contents
        self.boxSizer1 = wx.BoxSizer(orient=wx.HORIZONTAL)
        self.boxSizer1.AddWindow(self.button1, 0, border=15,
flag=wx.ALL)
        self.boxSizer1.AddWindow(self.textCtrl1, 1,
border=15, flag=wx.ALL | wx.EXPAND )
        self.boxSizer1.AddWindow(self.classedpanel, 1,
border=15, flag=wx.ALL | wx. EXPAND)
        self.panel1.SetSizer(self.boxSizer1)
        self.boxSizer1.Layout()
          
    def onNew(self, event):
        file = open('C:/Documents and
Settings/user/Desktop/tester.txt', 'r')
        contents = file.read()
        self.classedpanel.textCtrl1.SetValue(contents)

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = create(None)
    frame.Show()

    app.MainLoop()

I got the Layout() call to work, but you need to call it when you’re done
creating everything else. Delete the line "
self.boxSizer1.Layout()" and
replace it with either of these (but not both):

self.panel1.Layout()

Or

self.SetClientSize(self.panel1.GetBestSize())

Worked for me on Windows XP, wxPython 2.8.4.2

Mike, thanks very much! Works beautifully, particularly the second,
I have been unsure of what exactly to call Layout() on and this is a
big help.

CM

I got the Layout() call to work, but you need to call it when you're done
creating everything else. Delete the line "self.boxSizer1.Layout()" and
replace it with either of these (but not both):

You guys have come through as usual. Thanks for the time and effort to help us
novices out. It's much appreciated.