I hope this isn't terrible as I'm a few drinks in already (hey, it's
Thursday!). The Draw() method could undoubtedly be optimized.
from wxPython.wx import *
class TiledPanel(wxPanel):
def __init__(self, parent, id, image):
wxPanel.__init__(self, parent, id)
self.image = wxBitmapFromImage(image)
self.height, self.width = image.GetHeight(), image.GetWidth()
EVT_PAINT(self, self.OnPaint)
def OnPaint(self, event):
self.Draw(wxPaintDC(self))
def Draw(self, dc):
h, w = self.GetSize()
cols = w / self.width + 1 or 1
rows = h / self.height + 1 or 1
x = y = 0
for r in range(rows):
for c in range(cols):
dc.DrawBitmap(self.image, y, x, True)
x += self.width
y += self.height
x = 0
class Frame(wxFrame):
def __init__(self, parent, id, title):
wxFrame.__init__(self, parent, id, title)
image = wxImage('/usr/share/pixmaps/gnome-home.png',
wxBITMAP_TYPE_PNG)
panel = TiledPanel(self, -1, image)
class App(wxApp):
def OnInit(self):
wxInitAllImageHandlers()
frame = Frame(None, -1, "tiled image panel")
frame.Show(true)
return true
if __name__ == '__main__':
app = App()
app.MainLoop()
Now... somehow I missed the discussion of the new packaging scheme and
am not finding the discussion in the archives... someone care to
elaborate how I can use wx.Frame rather than wxFrame?
Cliff
···
On Thu, 2003-06-05 at 17:41, Kimberly Swinth wrote:
I'm a newbie to wxPython and I've been struggling with something for
several days now and was hoping maybe someone out there could help me
with something.
I want to add a background image to one of my frames. I can add a
static image fine. But when I resize the window, the image gets
distorted. So what I really want to do is use a tileable image. In
addition, I want to be able to add other object on top of the image,
and I can't figure out how to do that. I'm a pretty novice
programmer, so there is probably a very simple answer to this
question, but I've been beating my head against the wall for days on
this! The way I'm thinking about this, is I want to do what you do
with a webpage, where you set the background image for the page, and
then you build on top of that. Can this be done in wxPython?
Any help is GREATLY appreciated!
Kim