SoFunction
Updated on 2024-10-29

Implementation of embedding image files into wxpython code

Below directly on the code to stay, easy to access later reuse.

# -*- coding: utf-8 -*- 
# Author: LeniyTsan
#Time: 2014-07-17
 
import wx
from  import PyEmbeddedImage
 
class MyFrame1 (  ):
  def __init__( self, parent ):
    .__init__ ( self, parent )
    ( ( wx.SYS_COLOUR_3DLIGHT ) )
    bSizer1 = (  )
    file = open('', 'rb')
    b64 = ().encode('base64')
    ()
    bitmap = PyEmbeddedImage(b64).GetBitmap()
    self.m_bitmap1 = ( self, wx.ID_ANY, bitmap )
    ( self.m_bitmap1, 0, |wx.ALIGN_CENTER_HORIZONTAL, 5 )
    ( bSizer1 )
    ()
    ( self )
    (  )
app = ()
gui = MyFrame1(None)
()
() 

The key part is the bitmap = PyEmbeddedImage(b64).GetBitmap() code, where b64 is the base64 string of the image generated earlier, and bitmap is our image object that allows the call.

The program runs with the following results: