繁体   English   中英

wxpython菜单栏没有显示

[英]wxpython menu bar not displaying

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

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

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

将此添加到〜/ .bashrc:

export UBUNTU_MENUPROXY = 0

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

我有同样的问题,我无法看到菜单栏,因为它在那里的“任务栏”方式。 因此,如果您不想永久更改.bashrc文件,则可以将其添加到python脚本中

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

不知何故,它不是一个wxpython问题。 这是一个功能。 它应该以这种方式行为。

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

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

在此输入图像描述

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM