Ver Mensaje Individual
  #2 (permalink)  
Antiguo 21/07/2010, 15:38
Avatar de razpeitia
razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: Problema con combobox

Tienes que usar un StaticBitmap en vez de un BitmapButton

Aqui hay un ejemplo no me funciono a mi pero con unos cuantos cambios lo hice jalar.
Código Python:
Ver original
  1. import wx, os
  2.  
  3. class TestFrame(wx.Frame):
  4.     def __init__(self, *args, **kwargs):
  5.  
  6.         wx.Frame.__init__(self, *args, **kwargs)
  7.         # there needs to be an "Images" directory with one or more jpegs in it in the
  8.         # current working directory for this to work
  9.         self.jpgs = GetJpgList("image") # get all the jpegs in the Images directory
  10.         self.CurrentJpg = 0
  11.  
  12.         self.MaxSize = (200, 400)
  13.  
  14.         b = wx.Button(self, label= "Display next")
  15.         self.Bind(wx.EVT_BUTTON, self.DisplayNext)
  16.         # starting with an EmptyBitmap, the real one will get put there
  17.         # by the call to .DisplayNext()
  18.         self.Image = wx.StaticBitmap(self, bitmap=wx.EmptyBitmap(*self.MaxSize))
  19.         self.DisplayNext()
  20.  
  21.         # Using a Sizer to handle the layout: I never like to use absolute postioning
  22.         box = wx.BoxSizer(wx.VERTICAL)
  23.         box.Add(b, 0, wx.CENTER|wx.ALL, 10)
  24.  
  25.         # adding stretchable space before and after centers the image.
  26.         box.Add((1,1),1)
  27.         box.Add(self.Image, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALL|wx.ADJUST_MINSIZE, 10)
  28.         box.Add((1,1),1)
  29.  
  30.         #self.SetSizerAndFit(box)
  31.  
  32.         wx.EVT_CLOSE(self, self.OnCloseWindow)
  33.  
  34.     def DisplayNext(self, event=None):
  35.         # load the image
  36.         Img = wx.Image(self.jpgs[self.CurrentJpg], wx.BITMAP_TYPE_JPEG)
  37.  
  38.         # scale the image, preserving the aspect ratio
  39.         W = Img.GetWidth()
  40.         H = Img.GetHeight()
  41.         if W > H:
  42.             NewW = self.MaxSize[0]
  43.             NewH = self.MaxSize[0] * H / W
  44.         else:
  45.             NewH = self.MaxSize[0]
  46.             NewW = self.MaxSize[0] * W / H
  47.         Img = Img.Scale(NewW,NewH)
  48.  
  49.         # convert it to a wx.Bitmap, and put it on the wx.StaticBitmap
  50.         self.Image.SetBitmap(wx.BitmapFromImage(Img))
  51.  
  52.         # You can fit the frame to the image, if you want.
  53.         self.Fit()
  54.  
  55.         self.CurrentJpg += 1
  56.         if self.CurrentJpg > len(self.jpgs) -1:
  57.             self.CurrentJpg = 0
  58.  
  59.     def OnCloseWindow(self, event):
  60.         self.Destroy()
  61.  
  62.  
  63. def GetJpgList(dir):
  64.     jpgs = [f for f in os.listdir(dir) if f[-4:] == ".jpg"]
  65.     print "JPGS are:", jpgs
  66.  
  67.     return [os.path.join(dir, f) for f in jpgs]
  68.  
  69. class App(wx.App):
  70.     def OnInit(self):
  71.         frame = TestFrame(None, title="wxBitmap Test")
  72.         frame.Show(True)
  73.         return True
  74.  
  75. if __name__ == "__main__":
  76.     app = App(redirect=False)
  77.     app.MainLoop()