And because the code is in the revised on the basis of the others, so do not want to consult the data dictionary to do that again to the picture according to the number of images in the folder initialization ImageList adequately, the code must be in the for x in the range () in the manual input parameters to initialize the
import wx
The from PIL import Image
The import matplotlib. Pyplot as PLT
The import OS
The import tkinter
The import re
The import pygame
Data=https://bbs.csdn.net/topics/{0: "Zero", rank 1: "first," 2: "the second", 3: "three", 4: "four," 5: "five", 6: "six," 7: "seven", 8: "eight", 9: "nine", 10: "ten", 11: "eleven"}
# a dictionary
# h=0
The class MyFrame (wx. Frame) :
Def __init__ (self, parent=None) :
# h=1
Super (MyFrame, self) __init__ (parent, 1, "with the bitmap list", size=(1000, 1000)) # super can call the superclass and methods of the parent
Il=wx. ImageList (# 150300, True) to create image list
For f in OS. Listdir (r 'E: \ \ photo2) :
# h=h + 1
Img=wx. Image (r "E: \ photo2" + "\ " + f, wx. BITMAP_TYPE_BMP)
Img. Rescale (150300)
BMP=img. ConvertToBitmap ()
Il. The Add (BMP)
# s=il. GetBitmap (5)
# print (s)
The self. The list=wx. ListCtrl (self - 1, style=wx. LC_ICON | wx. LC_AUTOARRANGE)
Self. List. AssignImageList (il, wx IMAGE_LIST_NORMAL)
# h=self. List. InsertImageItem ()
# call InsertImageStringItem () method to access the list items, and introduced the string for the icon set
# the self. The Bind (wx. EVT_LIST_ITEM_SELECTED, PLT. Show, il [])
For x in range (11) :
Self. List. InsertImageStringItem (x, data [x], x)
# the self. The Bind (wx. EVT_LIST_ITEM_SELECTED, self courseListSelectFunc, self. List)
# the self. The Bind (wx. EVT_LIST_ITEM_SELECTED, PLT. Show, the self. The list)
=wx app. The app ()
Frame=MyFrame ()
Frame. The Show ()
App. MainLoop ()
# AssignImageList and InsertImageStringItem to create bitmap list
Now the result of the program is run as follows:
Try adding event before click on whichever figure can only show the last picture, so consult everybody bosses corresponding binding events