【问题标题】:wxpython menu bar not displayingwxpython菜单栏不显示
【发布时间】:2011-02-16 23:03:24
【问题描述】:

我正在尝试使用 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()

【问题讨论】:

  • 不看代码,没法说。
  • 在 Winxp、python 2.6 和 wx 2.8.10 下工作正常
  • 在这里也可以。如果禁用桌面效果会发生什么变化吗?过去我遇到过旧卡或过时驱动程序无法正确处理透明度的问题,导致一些界面元素消失。
  • 我也有同样的问题,但只针对一个窗口。 MenuBar 的所有其他功能都可以正常工作...

标签: wxpython


【解决方案1】:

我遇到了同样的错误,但我没有使用 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")

【讨论】:

  • 这也为我解决了问题。
【解决方案2】:

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

【讨论】:

    【解决方案3】:

    将此添加到 ~/.bashrc:

    导出 UBUNTU_MENUPROXY=0

    来自https://bugs.launchpad.net/ubuntu/+source/wxwidgets2.8/+bug/682478

    【讨论】:

    • 这是正确答案!不要忘记打开一个新终端,以便将更改考虑在内
    【解决方案4】:

    不知何故,这不是 wxpython 的问题。这是一个特点。它应该以这种方式运行。

    Apple 和 Microsoft 指定的菜单栏布局略有不同。 (Apple 规范。Microsoft 规范。) WxWidgets 将自动移动 Macintosh 上的某些菜单,以简化在 MS-Windows 和 Apple Macintosh 上编写具有本机外观和感觉的跨平台应用程序的任务;

    关于/退出菜单项将位于停靠菜单中。

    检查:https://wiki.wxpython.org/Optimizing%20for%20Mac%20OS%20X

    【讨论】:

      【解决方案5】:

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

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

      【讨论】:

        猜你喜欢
        • 2010-11-07
        • 2014-03-11
        • 2018-08-29
        • 1970-01-01
        • 1970-01-01
        • 2014-03-15
        • 2019-06-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多