2013-08-05 163 views
2

我在想如果有人能告訴我如何在提供的代碼中添加菜單欄。我的問題是我無法找到任何文檔或任何添加菜單欄到wx.panel。這甚至有可能嗎?如果你能告訴我那將會是多麼的棒。這裏是我的代碼: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() 

回答

2

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

+0

是的我知道,但我coundn't弄清楚如何將菜單欄作爲一個新的wxpython –

+0

看看這個教程,它顯示添加一個菜單http://www.python-forum.org/ viewtopic.php?f = 12&t = 516 – Yoriz

+0

是的,但你不知道我來自哪裏我不能添加一個菜單欄,除非我使用wxframe和im使用wxpannel我沒有得到如何使用兩個 –