您可以使用 EnableTop() 禁用整个菜单
代码示例:
import wx
class gui(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, None, id, title, style=wx.DEFAULT_FRAME_STYLE)
menuBar = wx.MenuBar()
file = wx.Menu()
quit = wx.MenuItem(file, 101, '&Quit\tCtrl+Q', 'Quit the Application')
about = wx.MenuItem(file, 102, '&About\tCtrl+A', 'About the Application')
help = wx.MenuItem(file, 103, '&Help\tCtrl+H', 'Help related to the Application')
file.AppendItem(help)
file.AppendSeparator()
file.AppendItem(about)
file.AppendSeparator()
file.AppendItem(quit)
file.AppendSeparator()
menuBar.Append(file, '&File')
self.SetMenuBar(menuBar)
menuBar.EnableTop(0, False)#Comment out this to enable the menu
#self.SetMenuBar(None)#Uncomment this to hide the menu bar
if __name__ == '__main__':
app = wx.App()
frame = gui(parent=None, id=-1, title="My-App")
frame.Show()
app.MainLoop()
另外,如果你使用self.SetMenuBar(None),整个菜单栏就会消失,如下所示。您可以使用这种快速而肮脏的方式切换菜单栏的显示/隐藏。要再次显示菜单栏,只需像self.SetMenuBar(menuBar) 一样再次设置它,然后菜单栏将再次可见。也可能有更好的方法。
希望对你有帮助。