1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#!/usr/bin/env python
#-*- coding: ISO-8859-1 -*-
import wx
class myApp(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)
hbox = wx.BoxSizer(wx.HORIZONTAL)
vbox1 = wx.BoxSizer(wx.VERTICAL)
vbox2 = wx.BoxSizer(wx.VERTICAL)
listImg = (("image1", "image1.jpg"), ("image2", "image2.jpg"),
("image3", "image3.jpg"), ("image4", "image4.jpg"))
text1 = wx.StaticText(self, -1, "liste des images:")
listBox = wx.ListBox(self, -1, size=(200, 300))
listBox.Bind(wx.EVT_LISTBOX, self.onImgChange)
text2 = wx.StaticText(self, -1, "Mon image sélectionnée:")
self.staticBitmap = wx.StaticBitmap(self, -1)
vbox1.Add(text1, 0, wx.ALIGN_CENTER)
vbox1.Add(listBox, 0, wx.ALIGN_CENTER)
vbox2.Add(text2, 0, wx.ALIGN_CENTER)
vbox2.Add(self.staticBitmap, 0, wx.ALIGN_CENTER)
hbox.Add(vbox1, 0, wx.RIGHT, 30)
hbox.Add(vbox2, 0)
self.SetSizer(hbox)
for imgName, imgPath in listImg:
i = listBox.Append(imgName)
listBox.SetClientData(i, imgPath)
self.Fit()
self.Centre()
self.Show(True)
def onImgChange(self, e):
bmp = wx.Bitmap(e.GetClientData())
self.staticBitmap.SetBitmap(bmp)
self.Fit()
app = wx.App()
myApp(None, -1, 'myApp title')
app.MainLoop() |
Partager