Hello all,
Please review these two piece of code and see why the latter doesnt resize as desired. When I add panel I find result becomes very strange. How can I resize widgets in a panel without such problem? Below are the two codes for simple editor

PROBLEMATIC CODE

import wx
ID_NEW = 10
ID_OPEN = 11
ID_CLOSE = 12
ID_SAVE = 13
ID_SAVE_AS = 14
ID_PAGE_SETUP = 15
ID_PRINT_PREVIEW = 16
ID_PRINT = 17
ID_EXIT = 18
ID_UNDO = 19
ID_REDO = 20
ID_SEARCH = 21
ID_SPELL = 22
ID_HELP = 23
class TextEditor(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(350, 600))
        # self/Text editor is now a Window with all attribute of a frame
        # create status bar
        self.CreateStatusBar()
        # set default status bar string
        self.SetStatusText("For help press F1")
        # define sizers
        vbox = wx.BoxSizer(wx.VERTICAL)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
                
        #Add menu
        #define menubar and menu
        menubar = wx.MenuBar()
        # attach menubar to the frame
        self.SetMenuBar(menubar)
        #define menus
        filemenu = wx.Menu()
        # Append items        
        filemenu.Append(ID_NEW, "&New", "New Blank file")
        filemenu.Append(ID_OPEN, "&Open", "Open  file")
        filemenu.Append(ID_CLOSE, "&Close", "Close file")
        #-----------------------------------------------
        filemenu.AppendSeparator()
        filemenu.Append(ID_SAVE, "&Save", "Save changes")
        filemenu.Append(ID_SAVE_AS, "Save As...", "Save to different location")
        #-----------------------------------------------------
        filemenu.AppendSeparator()
        filemenu.Append(ID_PAGE_SETUP, "Page set&up", "Set up properties before printing")
        filemenu.Append(ID_PRINT_PREVIEW, "Print pre&view", "Preview before printing")
        filemenu.Append(ID_PRINT, "&Print", "Print file")
        #-------------------------------------------------------
        filemenu.AppendSeparator()
        filemenu.Append(ID_EXIT, "E&xit", "Close the program")
        
        menubar.Append(filemenu, "&File")
        
        editmenu = wx.Menu()
        menubar.Append(editmenu, "&Edit")
        
        viewmenu = wx.Menu()
        menubar.Append(viewmenu, "&View")
        
        formatmenu = wx.Menu()
        menubar.Append(formatmenu, "F&ormat")
        
        toolsmenu = wx.Menu()
        menubar.Append(toolsmenu, "&Tools")
        
        helpmenu = wx.Menu()
        menubar.Append(helpmenu, "&Help")
        #------------------------------------
        # Add toolbars
        toolbar1 = wx.ToolBar(self, -1)
        toolbar1.SetToolBitmapSize((24,24 ))
        toolbar1.AddLabelTool(ID_SAVE, '', wx.Bitmap('save.png'))
        toolbar1.AddLabelTool(ID_UNDO, '', wx.Bitmap('undo.png'))
        toolbar1.AddLabelTool(ID_REDO, '', wx.Bitmap('redo.png'))        
        toolbar1.AddLabelTool(ID_SEARCH, '', wx.Bitmap('search.png'))
        toolbar1.AddLabelTool(ID_SPELL, '', wx.Bitmap('spellcheck.png'))
        toolbar1.AddLabelTool(ID_HELP, '', wx.Bitmap('help.png'))
        toolbar1.Realize()
        #---------------------------------------------------------
        #Add to sizer           
        vbox.Add(toolbar1, proportion = 0,flag = wx.EXPAND, border = 0 )   
        # put a panel
        TextPanel = wx.Panel(self, -1)    
        #create text editor
        editor_area = wx.TextCtrl(TextPanel, -1, style = wx.TE_MULTILINE)
        # Add to sizer
        hbox_editor_area = wx.BoxSizer(wx.HORIZONTAL)
        hbox_editor_area.Add(editor_area, proportion = 1, flag = wx.EXPAND, border = 0)
        vbox.Add(hbox_editor_area, 1, wx.EXPAND)
                
        TextPanel.SetSizer(vbox)
        TextPanel.Layout()
              
        #center the window
        self.Center()
        #show the window(without this the windows will not show up)
        self.Show(True)

#our main application
app = wx.App()
TextEditor(None, -1, "Text Editor")
app.MainLoop()

WORKING CODE WITHOUT PANEL

import wx
ID_NEW = 10
ID_OPEN = 11
ID_CLOSE = 12
ID_SAVE = 13
ID_SAVE_AS = 14
ID_PAGE_SETUP = 15
ID_PRINT_PREVIEW = 16
ID_PRINT = 17
ID_EXIT = 18
ID_UNDO = 19
ID_REDO = 20
ID_SEARCH = 21
ID_SPELL = 22
ID_HELP = 23
class TextEditor(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(350, 600))
        # self/Text editor is now a Window with all attribute of a frame
        # create status bar
        self.CreateStatusBar()
        # set default status bar string
        self.SetStatusText("For help press F1")
        # define sizers
        vbox = wx.BoxSizer(wx.VERTICAL)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
                
        #Add menu
        #define menubar and menu
        menubar = wx.MenuBar()
        # attach menubar to the frame
        self.SetMenuBar(menubar)
        #define menus
        filemenu = wx.Menu()
        # Append items        
        filemenu.Append(ID_NEW, "&New", "New Blank file")
        filemenu.Append(ID_OPEN, "&Open", "Open  file")
        filemenu.Append(ID_CLOSE, "&Close", "Close file")
        #-----------------------------------------------
        filemenu.AppendSeparator()
        filemenu.Append(ID_SAVE, "&Save", "Save changes")
        filemenu.Append(ID_SAVE_AS, "Save As...", "Save to different location")
        #-----------------------------------------------------
        filemenu.AppendSeparator()
        filemenu.Append(ID_PAGE_SETUP, "Page set&up", "Set up properties before printing")
        filemenu.Append(ID_PRINT_PREVIEW, "Print pre&view", "Preview before printing")
        filemenu.Append(ID_PRINT, "&Print", "Print file")
        #-------------------------------------------------------
        filemenu.AppendSeparator()
        filemenu.Append(ID_EXIT, "E&xit", "Close the program")
        
        menubar.Append(filemenu, "&File")
        
        editmenu = wx.Menu()
        menubar.Append(editmenu, "&Edit")
        
        viewmenu = wx.Menu()
        menubar.Append(viewmenu, "&View")
        
        formatmenu = wx.Menu()
        menubar.Append(formatmenu, "F&ormat")
        
        toolsmenu = wx.Menu()
        menubar.Append(toolsmenu, "&Tools")
        
        helpmenu = wx.Menu()
        menubar.Append(helpmenu, "&Help")
        #------------------------------------
        # Add toolbars
        toolbar1 = wx.ToolBar(self, -1)
        toolbar1.SetToolBitmapSize((24,24 ))
        toolbar1.AddLabelTool(ID_SAVE, '', wx.Bitmap('save.png'))
        toolbar1.AddLabelTool(ID_UNDO, '', wx.Bitmap('undo.png'))
        toolbar1.AddLabelTool(ID_REDO, '', wx.Bitmap('redo.png'))        
        toolbar1.AddLabelTool(ID_SEARCH, '', wx.Bitmap('search.png'))
        toolbar1.AddLabelTool(ID_SPELL, '', wx.Bitmap('spellcheck.png'))
        toolbar1.AddLabelTool(ID_HELP, '', wx.Bitmap('help.png'))
        toolbar1.Realize()
        #---------------------------------------------------------
        #Add to sizer           
        vbox.Add(toolbar1, proportion = 0,flag = wx.EXPAND, border = 0 )   
        # put a panel
        #TextPanel = wx.Panel(self, -1)    
        #create text editor
        editor_area = wx.TextCtrl(self, -1, style = wx.TE_MULTILINE)
        # Add to sizer
        hbox_editor_area = wx.BoxSizer(wx.HORIZONTAL)
        hbox_editor_area.Add(editor_area, proportion = 1, flag = wx.EXPAND, border = 0)
        vbox.Add(hbox_editor_area, 1, wx.EXPAND)
                
        self.SetSizer(vbox)
        self.Layout()
              
        #center the window
        self.Center()
        #show the window(without this the windows will not show up)
        self.Show(True)

#our main application
app = wx.App()
TextEditor(None, -1, "Text Editor")
app.MainLoop()

Thanks alot,
Steve

Just to add on that, I want to put my icons in a folder named icons in the same folder as my script. How do I reference them in code without error "File so and so.png does not exist"

Thanks again

Just to add on that, I want to put my icons in a folder named icons in the same folder as my script. How do I reference them in code without error "File so and so.png does not exist"

Thanks again

On Windows you do a "./icons/myicon.ico" for example.

This question has already been answered. Start a new discussion instead.