Skip to main content
 首页 » 编程设计

python之wx.Panel 带有菜单栏

2024年11月01日10zengkefu

我想知道是否有人可以告诉我如何将菜单栏添加到所提供的代码中。我的问题是我找不到任何关于向 wx.panel 添加菜单栏的文档或任何内容。这可能吗?如果你能告诉我那会很棒。这是我的代码:

class Panel1(wx.Panel): 
def __init__(self, parent, id): 
# create the panel 
    wx.Panel.__init__(self, parent, id) 
    try: 
        imageFile = 'resize.jpg' 
        data = open(imageFile, "rb").read() 
 
        stream = cStringIO.StringIO(data) 
 
        bmp = wx.BitmapFromImage( wx.ImageFromStream( stream )) 
        weather1 = "The current temp in Urbandale is %r" % (ob['tempF']) 
        weather2 = "With the heat index the temp in Urbandale is %r" % (ob['heatindexF']) 
        wx.StaticBitmap(self, -1, bmp, (0, 0)) 
        if ob['tempF'] >= '80': 
            label2 = wx.StaticText(self, -1, weather1 , wx.Point(20, 196)) 
        if ob['tempF'] <= '90': 
            label2 =  wx.StaticText(self, -1, weather2 , wx.Point(20, 196)) 
        label2.SetBackgroundColour("white") 
        jpg1 = wx.Image(imageFile, wx.BITMAP_TYPE_ANY).ConvertToBitmap() 
 
        wx.StaticBitmap(self, -1, jpg1, (10 + jpg1.GetWidth(), 5), (jpg1.GetWidth(), jpg1.GetHeight())) 
    except IOError: 
        print "Image file %s not found" % imageFile 
        raise SystemExit 
 
app = wx.PySimpleApp() 
frame1 = wx.Frame(None, -1, "Weather", size = (316, 435)) 
Panel1(frame1,-1) 
frame1.Show(1) 
app.MainLoop() 

请您参考如下方法:

菜单栏被添加到框架而不是面板,wxpython 演示有使用菜单栏的示例。