运行wxpython的示例代码,但菜单项不会显示

时间:2016-01-01 16:31:39

标签: macos wxpython

import wx

class MainWindow(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, title=title, size=(200,100))
        self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)
        self.CreateStatusBar() # A Statusbar in the bottom of the window

        # Setting up the menu.
        filemenu= wx.Menu()

        # wx.ID_ABOUT and wx.ID_EXIT are standard IDs provided by wxWidgets.
        filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")
        filemenu.AppendSeparator()
        filemenu.Append(wx.ID_EXIT,"E&xit"," Terminate the program")

        # Creating the menubar.
        menuBar = wx.MenuBar()
        menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar
        self.SetMenuBar(menuBar)  # Adding the MenuBar to the Frame content.
        self.Show(True)

app = wx.App(False)
frame = MainWindow(None, "Sample editor")
app.MainLoop()

我可以看到& File菜单,但它是空的。它不包含about和exit项。我在这里缺少什么?

以下是包含以下代码的原始Wiki页面:wxPython wiki

非常感谢。

另外:如果我用一些随机数替换ID_ABOUT和ID_EXIT,它就可以了。无论如何我不想这样做,因为它不是标准方式。

1 个答案:

答案 0 :(得分:0)

This question回答我的意见。它在那里创建菜单项,但我没有注意到,因为我没有仔细检查。感谢任何对此问题感兴趣的人

相关问题