How to add an image in the menu?

Asked

Viewed 170 times

3

I need to add an image to the menu of my program in Python. I am using the wxpython library. The menu is 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 in the menu, at the top, aligned to the center, which is this:

Can someone help me with that? I’ve been doing my research all day and I couldn’t. It would be better if it were with picture buttons, because I will need to add others later.

1 answer

1


See if this passage 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 pulled out of that here looks good...

Vlw I hope it helps

Something is going on...

  • worked, the problem was the gray background I put, was capping the image. Thank you!

  • @Ivoqueiroz if any of the answers is correct, could validate it by clicking on the green icon below the evaluation arrows... Vlw...

  • thanks! you know how I can position this image in the menu?

  • Open a new question, sometimes other users can search for this question too, when formulating the question, see if you already have no answer...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.