My first time in the forums. I started with the hello world extended sample code, the snippet that used menus. I wanted to extend that into something more like what I am intending to create. When I added more ‘non-stock’ items under the file menu, they don’t show up. In fact, I can’t get any other items to show up. Example code below:
Did you do a MenuBar and attach the Menu to the bar?
Here is an example:
import wx
def main():
app = wx.App(False) # Create a new app, don't redirect stdout/stderr to a window.
frame = wx.Frame(None, wx.ID_ANY, "Menu Testing") # A Frame is a top-level window.
# Menubar for the frame
menuBar = wx.MenuBar()
# Menu in the menubar
fileMenu = wx.Menu()
# Custom item
# item = wx.MenuItem(parentMenu=fileMenu, id=wx.ID_ANY, text="TestItem", helpString="This Better Work...", kind=wx.ITEM_NORMAL)
# # Set custom item settings
# # item.SetBitmap(...)
# # Append the item to the menu (AppendItem is deprecated)
# fileMenu.Append(item)
mniItem0 = wx.MenuItem(fileMenu, wx.ID_ANY, "mni1", "This Better Work...")
# You had two mniItem1 ...
# mniItem1 = wx.MenuItem(fileMenu, wx.ID_ANY, "mni1", "This Better Work...")
mniItem1 = wx.MenuItem(fileMenu, wx.ID_ANY, "mni2", "This Better Work...")
mnuItem2 = wx.MenuItem(fileMenu, wx.ID_ANY, "mni3", "This Better Work...")
mnuItem3 = wx.MenuItem(fileMenu, wx.ID_ANY, "mni4", "This Better Work...")
mnuItem4 = wx.MenuItem(fileMenu, wx.ID_ANY, "mni5", "This Better Work...")
mnuItem5 = wx.MenuItem(fileMenu, wx.ID_ANY, "mni6", "This Better Work...")
mnuItem6 = wx.MenuItem(fileMenu, wx.ID_ANY, "mni7", "This Better Work...")
fileMenu.Append(mniItem0)
fileMenu.Append(mniItem1)
fileMenu.Append(mnuItem2)
fileMenu.Append(mnuItem3)
fileMenu.Append(mnuItem4)
fileMenu.Append(mnuItem5)
fileMenu.Append(mnuItem6)
# Attach the menu to the menubar
menuBar.Append(fileMenu, "&TestMenu")
# Attached to the frame (the magic that makes the menus show up)
frame.SetMenuBar(menuBar)
# status bar at the bottom to see the help string we created.
statusbar = frame.CreateStatusBar()
frame.Show(True) # Show the frame.
app.MainLoop()
if __name__ == "__main__":
main()
Example output:
I corrected two things in your example. You had mniItem1 twice and you were using AppendItem instead of Append.