2

I'm using Python 2.7. I need to display a .png image file in wxpython, such that the transparency is preserved, and you can still see the controls behind the transparent part of the image. This needs to work in Windows, Mac, AND Linux.

CodeMouse92
  • 6,840
  • 14
  • 73
  • 130

2 Answers2

2

I just wanted to add how to draw a png with transparencies normally, for those who google and come across this (as I did) so they dont end up thinking its not possible because of the accepted answer (as I did)

import wx

dc = wx.PaintDC(self)
self.pngimage = wx.Bitmap('image.png', wx.BITMAP_TYPE_PNG)
dc.DrawBitMap(self.pngimage, x, y)

this is what I do, and all the transparencies are displayed perfectly. I'm using wxpython 2.9.4.0

Dux
  • 1,226
  • 10
  • 29
Daniel H
  • 389
  • 4
  • 19
0

Why would you have the image over the controls. I would put the controls to the side, on top or under the image. There have been several threads on pngs and transparency on the wxPython list lately: https://groups.google.com/forum/#!topic/wxpython-users/ANZGyF0kkZ0

or https://groups.google.com/forum/#!topic/wxpython-users/_X2zhlTj_Fg

Maybe one of those will help you too.

Mike Driscoll
  • 32,629
  • 8
  • 45
  • 88
  • My project is more along the lines of a game,not a standard application (do not refer me to GameDev, please, they cannot help me.) And, while I am assuming from the links that a mask might be helpful, neither gives me a straight answer. – CodeMouse92 Jul 18 '11 at 21:29
  • I would think pygame or pyglet would be better suited to doing a game then wxPython. – Mike Driscoll Jul 19 '11 at 00:23
  • I don't need someone recreating my project or picking different tools for me. I need an answer for my question. – CodeMouse92 Jul 19 '11 at 00:35
  • I guess I should have worded that better. wxPython is for desktop GUIs, not for games. While I have seen people on the mailing list use it for games, they are usually embedding something else, like OpenGL or vpython. – Mike Driscoll Jul 19 '11 at 12:50
  • I already explored pygame and pyglet, and while they may contain a handful of tools I may use, my needs are not that of a typical game. I've written my own game core to fit my needs, and I rely so heavily on cross-platform video and transparent PNGs, the capablities of pygame-compatible GUIs are not cutting it. As it is, I'm starting to move towards PyGTK now instead. – CodeMouse92 Jul 19 '11 at 20:58