0

Dear members,
i have a question.
I created my software (with windows made with wxpython) and with py2exe I embed the icon into the exe.
Since I would like to add the same icon file (or any other image) also as decoration in the window but I don't want to let the icon file outside the "None" zip file that py2exe generates, is there a way to do this?
I mean, may I access a bitmap from the py2exe archive and use it inside a wxpython window?
Sorry but I don't know how else to explain it.
Thanks for your help,
G.

2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by Lardmeister
0

The Python module base64 allows you to convert image data to a string that can be included in your code. Here is an example from vegaseat I saved a while ago:

# playing with wxPython's
# wx.BitmapButton(parent, id, bitmap, pos, size, style)
# for a small image it is best to embed as base64 encoded string
# vega

import wx
import cStringIO
import base64

class MyFrame(wx.Frame):
    def __init__(self, parent, mytitle, data_stream):
        wx.Frame.__init__(self, parent, -1, mytitle, size=(400, 300))

        # convert data_stream to a bitmap
        bmp = wx.BitmapFromImage(wx.ImageFromStream(data_stream))
        # create a BitmapButton
        self.button = wx.BitmapButton(self, wx.ID_ANY, bitmap=bmp,
            pos=(10, 20),
            size=(bmp.GetWidth()+15, bmp.GetHeight()+15))

"""
# the base64 image string has been created with this short
# program, the resulting string is then copied and pasted
import base64
jpg_file = "Btn_next.jpg"
jpg2base64string = base64.encodestring(open(jpg_file,"rb").read())
print "Btn_next_jpg_b64='''\\\n" + jpg2base64string + "'''"
"""

Btn_next_jpg_b64='''\
/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcU
FhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgo
KCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAA7ADsDASIA
AhEBAxEB/8QAHAAAAgIDAQEAAAAAAAAAAAAABggFBwECBAAJ/8QAOhAAAQMDAgMFAwsDBQAAAAAA
AQIDBAAFEQYhEjFBBxNRYYEUInEVIzJCQ1JikaG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X3Vcftbb3dgEcSQhaT73T6QpmtXg5k5QnrbwjNNWF27
PpLiy3EQfnHcbqxzCR1P7eu9sQVRrXCbiwkJaZbGAlP7nzoKi3NtppDbYShCRgJSMAfCt3bykJ2X
TRj1OXkznc/0goul4wwoFfr4ef70QaS0qLlp2HMdWUKeClcPlxHH6YqrbM3I1RqGLaYSlcbqsuLH
JtsfSUfTl54HWmdiR2YsVmOwgIZZQG0J8EgYA/IUJy8j8bi9k2zW6QY1zgyIM9hD8WQ2W3GljZST
zFKT2sditz026/NsrTtyseeJKkJ4nYw8FJG5A+9v504NeO9SRqtafNxtpyOslpW3hnP69amrdfHY
+zmccqcjtE7PtKXa2S502yRTMQgqDzQLSifMoIz65pPNSwY8S89xHb4GiAeHiJ646/CimTcE/ZJo
1IkJHvkbVMaWh3zWlw9k07DXIwcOPqylpr/Uvp8OZ86sjsS7O9K3tC5F2tDct1tOR3rrhTzHNPFg
+opiIEGLbYjcW3xmYsZsYQ0ygISn4AbUewvwRBTs00JE0XbCkO+1XJ8AyZRTw8X4UjokfyaMsjqQ
DW1YpPZVfj4R/9k=
'''

# convert to jpg image bytes
jpg_bytes = base64.b64decode(Btn_next_jpg_b64)
# convert image bytes to data stream
data_stream = cStringIO.StringIO(jpg_bytes)

app = wx.App(0)
caption = 'wx.BitmapButton() with b64 image'
MyFrame(None, caption, data_stream).Show()
app.MainLoop()
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.