wxpython菜单栏不显示

发布于 2024-10-17 21:55:28 字数 2203 浏览 5 评论 0原文

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

I am trying to write a timetabling program using wxpython for gui and am using the getting started tutorial on the wxpython wiki to get up to speed with wxpython but when I try to add a menu bar to wxFrame, the menu bar does not show. Any ideas why this is happening?
I am using ubuntu 10.10 and python 2.7. The code is given below:

#! /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()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

执笏见 2024-10-24 21:55:28

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

I had the same error and I solved it no using standard IDs provided by wxWidgets.

Try with this:

# 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")
随遇而安 2024-10-24 21:55:28

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

Someone had a similar issue on the wxPython list. I think the menu was appearing in the "taskbar" or something because the OS had been configured for that, kind of like a Mac. If you're using a custom theme, try a standard one instead. You can also try running the wxPython demo to see if it has the same issue.

悲凉≈ 2024-10-24 21:55:28

将其添加到 ~/.bashrc:

导出 UBUNTU_MENUPROXY=0

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

add this to ~/.bashrc:

export UBUNTU_MENUPROXY=0

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

戴着白色围巾的女孩 2024-10-24 21:55:28

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

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

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

输入图片此处描述

检查:https://wiki.wxpython。 org/优化%20for%20Mac%20OS%20X

Somehow it is not a wxpython problem. It is a feature. It is supposed to behavior in this way.

Apple and Microsoft specify slightly different layouts for menubars. (Apple specification. Microsoft specification.) WxWidgets will automatically move certain menus on a Macintosh, to ease the task of writing cross-platform applications with native look and feel on both MS-Windows and Apple Macintosh;

The About/Exit menu item would locate at the dock menu.

enter image description here

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

恬淡成诗 2024-10-24 21:55:28

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

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

I had the same problem where i could not see the menu bar because it as in the "taskbar" way up there. So you can just add this to your python script if you do not want to permanantly change your .bashrc file

import os
os.environ["UBUNTU_MENUPROXY"]="0"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文