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):
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我遇到了同样的错误,但我没有使用 wxWidgets 提供的标准 ID 解决了这个问题。
尝试用这个:
I had the same error and I solved it no using standard IDs provided by wxWidgets.
Try with this:
有人在 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.
将其添加到 ~/.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
不知何故,这不是 wxpython 问题。这是一个特点。它应该以这种方式表现。
关于/退出菜单项将位于停靠菜单中。
检查: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.
The About/Exit menu item would locate at the dock menu.
Check: https://wiki.wxpython.org/Optimizing%20for%20Mac%20OS%20X
我遇到了同样的问题,我看不到菜单栏,因为它位于“任务栏”上方。因此,如果您不想永久更改 .bashrc 文件,则可以将其添加到 python 脚本中
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