Question

I have a folder containing a number of .jpg files (each of them are 100x100 pixels).

I would like to create a wxPython panel showing all these .jpg (with a mosaic layout) as wx.BitmapButton.

I tried with the wxPython's demo called BitmapButton.py but this loads images from embedded image only, here I don't know what's the canonical way to do it with JPEGs.

Moreover, I would like this panel to automatically give a good disposition of the buttons.

Example : let's assume I have 10 buttons.

  • If window's width is large enough to fit 5 buttons per row, 2 rows of 5 buttons should be displayed,
  • If the window is resized to a smaller width, then 2 rows of 4 buttons + 1 row of 2 buttons should be displayed, etc.

How to deal with JPEGs in wx.BitmapButton, and if many buttons, how to make that they have automatically a good layout in the panel (auto alignement in rows) ?

enter image description here

Was it helpful?

Solution

Yes, there is a new sizer that can do what you want in wxPython 2.9+ called WrapSizer. There is an example of its usage in the wxPython demo. You can also read about it at the following:

As for the BitmapButton, I am pretty sure you can pass it a jpg file if you do it properly. You will probably need to do something like this:

img = wx.Image(filepath, wx.BITMAP_TYPE_ANY)
bmp = wx.BitmapFromImage(img)
b = wx.BitmapButton(self, -1, bmp, (20, 20),
                   (bmp.GetWidth()+10, bmp.GetHeight()+10))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top