On Nov 29, 2:30 pm, Bart <[EMAIL PROTECTED]> wrote: > Dear members, > It's not (yet) easy to find my way through the bunch of info scattered > over the internet to find out how to embed an icon. It could be that > I’m looking at the wrong places, I'm new to Python and wxPython. > Nevertheless, I would like to share this little script with the rest > of the world. Any suggestions are welcome! > > Regards, > Bart > > import wx > import cStringIO > import base64 > > def getImageStream(): > img_b64 = \ > > """iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAAATlJREFUWIXNl2FyhCAMhV > +0B/NmCzfrHkxff+zSik0gCI77ZhwdCckHQoIi04w7Nd0a/ > WMBuK0cHcjyKdYa4LZSplmanBXsrTYTQOvonZljHys4AHx5HWVgTBx5syjWpeBVgN+A75H/ > BTbsmEBe9rXgQNcuqPp2qQqgj74cPJl61sxn5oGyxkx9B8BYZQDcVqbL7kLEGP691d55fGfb0LNtzsr0LdNcvQAQAPcKIZAESWTP5MsWAD2+b18DxVqwl5YPYowAgMcj7By > +787P2T0D+ > +Bn5AZIIxKt4iSbxtE3AVylywFq9cBdjADf1B5tZJqlBFEEsE4zaR0sy4Ln8xsxBvUw4oEwAWpHqVZZEOap > +Iq0rPlUAa6sCS6AkrR8EELI2pr8nfk3bP0vGA5wBOn5ZF0AI3R7Kv4BLsO1PPzEcJMAAAAASUVORK5CYII=""" > img = base64.b64decode(img_b64) > return img > > class MyFrame(wx.Frame): > def __init__(self, parent, id, caption): > wx.Frame.__init__(self, parent, id, caption) > > myStream = cStringIO.StringIO(getImageStream()) > myImage = wx.ImageFromStream(myStream) > myBitmap = wx.BitmapFromImage(myImage) > > myIcon = wx.EmptyIcon() > myIcon.CopyFromBitmap(myBitmap) > self.SetIcon(myIcon) > > app = wx.PySimpleApp() > frame = MyFrame(None, -1, "Embedded Programm Icon Sample") > frame.Show(True) > app.MainLoop()
wxPython provides the img2py utility for this sort of thing. On my Windows box, it was here: L:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\tools You can read up on how to use it here: http://www.blog.pythonlibrary.org/?p=34 Unfortunately, that article is a little dated. The newest version of wxPython includes an updated img2py utility that I'm told supports the previous API, but I haven't tested it. One of these days, I'll have to update that post to reflect the new way though... Glad you found an alternate way to do it though. I recommend subscribing to the wxPython group. They can give you additional pointers, should you need them: http://wxpython.org/maillist.php Mike -- http://mail.python.org/mailman/listinfo/python-list