gpt4 book ai didi

wxpython菜单栏不显示

转载 作者:行者123 更新时间:2023-12-02 21:34:41 25 4
gpt4 key购买 nike

我正在尝试使用 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菜单栏不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5023255/

25 4 0