How do I create a wxMenu submenu?

A very simple question from someone just starting out with wxPython,
how can I append a submenu to a menu item? I have created a separate
wxMenu and appended items to it. But when I attempt to append it to
the parent menu I get a message that it has raised an exception. This
must be a common newbie error. This is the line I am using to append
the previously defined wxMenu:

       FileMenu.Append(ID_MODE,"&Mode",ModeMenu,"Choose a mode.")

where ModeMenu was previously declared and had items appended to it.

A very simple question from someone just starting out with wxPython,
how can I append a submenu to a menu item? I have created a separate
wxMenu and appended items to it. But when I attempt to append it to
the parent menu I get a message that it has raised an exception. This
must be a common newbie error. This is the line I am using to append
the previously defined wxMenu:

       FileMenu.Append(ID_MODE,"&Mode",ModeMenu,"Choose a mode.")

where ModeMenu was previously declared and had items appended to it.

I'm not sure if you call Append() correctly.

From the wxPython demo:

(Demo->Core Windows/Controls->Menu)

        # 2nd menu from left
        menu2 = wx.Menu()
        menu2.Append(201, "Hydrogen")
        menu2.Append(202, "Helium")
        # a submenu in the 2nd menu
        submenu = wx.Menu()
        submenu.Append(2031,"Lanthanium")
        submenu.Append(2032,"Cerium")
        submenu.Append(2033,"Praseodymium")
        menu2.AppendMenu(203, "Lanthanides", submenu)
        # Append 2nd menu
        menuBar.Append(menu2, "&Elements")

Hope that helps.

Harald Stürzebecher

···

2005/6/15, Richard Querin <rfquerin@gmail.com>:

Try using AppendMenu instead of Append. Python cannot use overloaded
methods so there are seperate calls for Append, AppendMenu and
AppendItem. I use the following code:

            self.toolsMENU = wx.Menu()
            self.machinesMENU = wx.Menu()
            self.materialsMENU = wx.Menu()
            self.moldsMENU = wx.Menu()
        
            self.toolsMENU.AppendMenu(-1, "Machines", self.machinesMENU)
            self.toolsMENU.AppendMenu(-1, "Molds", self.moldsMENU)
            self.toolsMENU.AppendMenu(-1, "Materials", self.materialsMENU)

            self.addMachinesMENU = wx.MenuItem(self.machinesMENU, 101,
"Add Machine", "", wx.ITEM_NORMAL)
            self.delMachinesMENU = wx.MenuItem(self.machinesMENU, 102,
"Remove Machine", "", wx.ITEM_NORMAL)
            self.alterMachinesMENU = wx.MenuItem(self.machinesMENU,
103, "Alter Machine", "", wx.ITEM_NORMAL)
            self.machinesMENU.AppendItem(self.addMachinesMENU)
            self.machinesMENU.AppendItem(self.delMachinesMENU)
            self.machinesMENU.AppendItem(self.alterMachinesMENU)

-MattK