python – How to add an image to the menu?

Question:

I need to add an image to my Python program's menu. I'm using the wxpython library. The menu looks like this:

The code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import wx


class Frame(wx.Frame):
    title = "SEA"
    def __init__(self):
        wx.Frame.__init__(self, None, title=self.title, size=(800, 600))
        self.panel1 = wx.Panel(self, -1)
        self.createMainPanel()
        self.createMainMenu()
        self.Centre()

    def createMainPanel(self, color=(0, 0, 0)):
        panel = wx.Panel(self, id=wx.ID_ANY, pos=(0, 0), size=self.GetSize())
        panel.SetBackgroundColour('GRAY')

class App(wx.App):
    def OnInit(self):
        self.mainScreen = Frame()
        self.SetTopWindow(self.mainScreen)
        self.mainScreen.Show()

        return True  

if __name__ == '__main__':
    app = App(False)
    app.MainLoop()

I want to add the following image to the menu, at the top, aligned to the center, which is this:

Can anyone help me with this? I searched all day and I couldn't. It would be better if it was with image buttons, as I will need to add others later.

Answer:

See if this excerpt helps you:

self.bitmap = wx.Bitmap('imagem.jpg')
        wx.EVT_PAINT(self, self.OnPaint)

        self.Centre()

    def OnPaint(self, event):
        dc = wx.PaintDC(self)
        dc.DrawBitmap(self.bitmap, 60, 20)

I removed this tutu here looks good

vlw hope it helps

Anything goes on commenting…

Scroll to Top