wxpython菜单栏未显示

wxpython菜单栏未显示,wxpython,Wxpython,我正在尝试使用wxpython for gui编写一个时间表程序,并且正在使用wxpython wiki上的入门教程来了解wxpython,但是当我尝试向wxFrame添加菜单栏时,菜单栏不会显示。知道为什么会这样吗? 我正在使用ubuntu 10.10和python 2.7。代码如下: #! /usr/bin/env python2.7 import wx, os class MainWindow(wx.Frame): def __init__(self, parent, title

我正在尝试使用wxpython for gui编写一个时间表程序,并且正在使用wxpython wiki上的入门教程来了解wxpython,但是当我尝试向wxFrame添加菜单栏时,菜单栏不会显示。知道为什么会这样吗? 我正在使用ubuntu 10.10和python 2.7。代码如下:

#! /usr/bin/env python2.7
import wx, os

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


        # Creating the menubar.
        menuBar = wx.MenuBar()

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

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

        menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar
        self.SetMenuBar(menuBar)  # Adding the MenuBar to the Frame content.

        # Set events.
        self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)
        self.Bind(wx.EVT_MENU, self.OnExit, menuExit)

        self.Show(True)


    def OnAbout(self,e):

        # A message dialog box with an OK button. wx.OK is a standard ID in wxWidgets.
        dlg = wx.MessageDialog( self, "A small text editor", "About Sample Editor", wx.OK)
        dlg.ShowModal() # Show it
        dlg.Destroy() # finally destroy it when finished.

    def OnExit(self,e):
        self.Close(True)  # Close the frame.
        ''' 
        # 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()

wxPython列表上也有类似的问题。我认为菜单出现在“任务栏”或其他地方是因为操作系统已经为此进行了配置,有点像Mac。如果您使用的是自定义主题,请尝试使用标准主题。您还可以尝试运行wxPython演示,看看它是否有相同的问题。

我也有相同的错误,我没有使用wxWidgets提供的标准ID来解决它

试试这个:

# wx.ID_ABOUT and wx.ID_EXIT are standard ids provided by wxWidgets.
menuAbout = filemenu.Append(102, "&About"," Information about this program")
menuExit = filemenu.Append(103,"E&xit"," Terminate the program")
将此添加到~/.bashrc:

导出UBUNTU\u MENUPROXY=0


我遇到了同样的问题,我看不到菜单栏,因为它位于“任务栏”的上方。因此,如果不想永久性地更改.bashrc文件,可以将其添加到python脚本中

import os
os.environ["UBUNTU_MENUPROXY"]="0"

不知何故,这不是一个wxpython问题。这是一个特点。它的行为应该是这样的

苹果和微软为菜单栏指定的布局略有不同。(Apple specification.Microsoft specification.)WxWidgets将自动移动Macintosh上的某些菜单,以简化在MS Windows和Apple Macintosh上编写具有本机外观的跨平台应用程序的任务

“关于/退出”菜单项将位于停靠菜单


检查:

如果看不到代码,就不可能说。在Winxp、python 2.6和wx 2.8.10下也可以正常工作。如果禁用桌面效果,有什么变化吗?我曾经遇到过旧卡或过时的驱动程序不能正确处理透明度的问题,导致一些界面元素消失。我也有同样的问题,但只针对一个窗口。所有其他菜单栏工作正常…这是正确的答案!别忘了打开一个新的终端,所以要考虑到变化。这也为我修复了它。