wx.带有菜单栏的面板

问题描述 投票:0回答:2

我想知道是否有人可以向我展示如何向提供的代码添加菜单栏。我的问题是我找不到任何有关向 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()
python wxpython
2个回答
2
投票

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


0
投票

我将为您提供一个带有面板和两个按钮的菜单栏示例。

# -*- coding: utf-8 -*-
import wx

class MiVentana(wx.Frame):
    def __init__(self, parent, title, size):
        super().__init__(parent=parent, title=title, size=size)

        #Menús
        barra_menu = wx.MenuBar()
        # Creamos los menús
        menu_archivo = wx.Menu()
        # Agregamos a los menús
        abrir_archivo = menu_archivo.Append(wx.ID_OPEN, 'Abrir Archivo')
        # Agregando a la barra_menu
        barra_menu.Append(menu_archivo, '&Archivo')
        # Añadiendo los menús a la barra
        self.SetMenuBar(barra_menu)

        # Creando los controles restantes
        self.panel = wx.Panel(self)
        self.bsz = wx.BoxSizer(wx.VERTICAL)
        btn1 = wx.Button(self.panel, -1, u'botón1')
        btn2 = wx.Button(self.panel, -1, u'botón2')

        # Agregando al sizer principal
        self.bsz.Add(btn1, 1, flag=wx.EXPAND|wx.ALL, border=5)
        self.bsz.Add(btn2, 1, flag=wx.EXPAND|wx.ALL, border=5)

        # Relación panel sizer
        self.panel.SetSizer(self.bsz)

        # Configuración de la Ventana
        self.Center()
        self.Show()


if __name__ == '__main__':
    app = wx.App()
    frame = MiVentana(None, u'Recuerda Agenda', (400,400))
    app.MainLoop()
© www.soinside.com 2019 - 2024. All rights reserved.