I was making a simple application with a GUI built with wxPython. I have created and layed out the main menu, and when the user clicks a button, it is *supposed* to make a different set of controls appear, getting rid of/hiding the main menu. I was wondering how to do this. The function fires, but the results appear behind the main menu, and if I click again, they appear on top. This means the set of controls that the main menu is made of don't actually go away. Does anyone know what's wrong? Here's my entire code (It is my first attempt at wxPython, so if it looks badly strutured, please tell me - I'm not sure how it's supposed to be typed i.e. def or class...):

import os
import wx
import wx.html

class MainWindow(wx.Frame):
    
    def __init__(self, title):
        super( MainWindow, self ).__init__( None, size=(475,400), title=title )
        self.SetBackgroundColour( "white" )
        self.MainMenu()
        self.Show( True )



    def MainMenu(self):            
        # Title image panel
        self.panel1 = wx.Panel( self, 1, (0,0), (475,175) )
            
        titleImgLoc = wx.Image( "Images/Title.png", wx.BITMAP_TYPE_ANY ).ConvertToBitmap()
        self.titleImg = wx.StaticBitmap( self.panel1, -1, titleImgLoc, (0,0), (475,175) )
            
        self.sizer1 = wx.BoxSizer( wx.VERTICAL )
        self.sizer1.Add( self.titleImg, 0 )
        self.panel1.SetSizerAndFit( self.sizer1 )       

        # Buttons panel
        self.panel2 = wx.Panel( self, 2, (20,250), (425,90) )
            
        self.newBtn = wx.BitmapButton( self.panel2, 100, wx.Image("Images/Icons/add button.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap(),
                                     wx.EVT_BUTTON( self.panel2, 100, self.AddRecipe ) )
        self.newBtn.SetToolTip( wx.ToolTip("Add a new recipe.") )
            
        self.viewBtn = wx.BitmapButton( self.panel2, 200, wx.Image("Images/Icons/view button.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap(),
                                     wx.EVT_BUTTON( self.panel2, 200, self.ViewRecipe ) )
        self.viewBtn.SetToolTip( wx.ToolTip("View your list of recipes.") )

        self.searchBtn = wx.BitmapButton( self.panel2, 300, wx.Image("Images/Icons/search button.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap(),
                                     wx.EVT_BUTTON( self.panel2, 300, self.SearchRecipe ) )
        self.searchBtn.SetToolTip( wx.ToolTip("Search your list of recipes.") )
                   
        self.sizer2 = wx.FlexGridSizer( 1, 3, 50, 50 )
        self.sizer2.Add( self.newBtn, 0, wx.EXPAND )
        self.sizer2.Add( self.viewBtn, 1, wx.EXPAND )
        self.sizer2.Add( self.searchBtn, 2, wx.EXPAND )
        self.panel2.SetSizerAndFit( self.sizer2, wx.SHAPED )
            
        # HTML Window panel
        self.panel3 = wx.Panel( self, 3, (0,340), (475,50) )
            
        self.htmlWin = wx.html.HtmlWindow( self.panel3, 100, (0,0), (475,50) )
        self.htmlWin.SetPage( "<center><font size=2>Recipe Book &copy; "
                                  "2007 Erik Shadwick. All Rights Reserved.</font></center>" )
        self.sizer3 = wx.BoxSizer( wx.HORIZONTAL )
        self.sizer3.Add( self.htmlWin, 0, wx.SHAPED )
        self.panel3.SetSizerAndFit( self.sizer3, wx.SHAPED )



    def AddRecipe(self,e):
        # Title image panel
        self.panel1 = wx.Panel( self, 1, (0,0), (475,100) )
            
        addImgLoc = wx.Image( "Images/Add Recipe.png", wx.BITMAP_TYPE_ANY ).ConvertToBitmap()
        self.addImg = wx.StaticBitmap( self.panel1, -1, addImgLoc, (0,0), (475,100) )
            
        self.sizer1 = wx.BoxSizer( wx.VERTICAL )
        self.sizer1.Add( self.addImg, 0 )
        self.panel1.SetSizerAndFit( self.sizer1 )



    def ViewRecipe(self,e):
        print "ViewRecipe"
        # Finish this function...



    def SearchRecipe(self,e):
        print "SearchRecipe"
        # Finish this function...

            

    def SaveRecipe(self,e):
        print "SaveRecipe"
        # Finish this function...


            
    def OnAbout(self,e):
        print "OnAbout"
        # Finish this function...


# Other code
app = wx.PySimpleApp()
frame = MainWindow("Recipe Book")
frame.Move(wx.Point(150, 150))
frame.Show()
app.MainLoop()

SOLVED: I see what I did wrong. I finally found a tutorial on building an application like this, and got it all figured out. Thanks anyway to anyone who looked at this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.