使用wxpython实现的一个简单图片浏览器实例

2019-10-06 11:49:22丽君

                    else:
                        nnjpgs.append(_dir)
        jpgs.sort()
        for _jpgs in jpgs:
            self.list.Append(str(_jpgs)+'.jpg')
        for _nnjpgs in nnjpgs:
            self.list.Append(_nnjpgs)
        for _dirs in dirs:
            self.list.Append(_dirs)

        os.chdir(dir)#设置工作路径

    #获得下一张要显示的图片
    def GetNextImage(self):
        index = self.list.GetSelection()
        i = index
        while i+1<self.list.GetCount():
            i += 1
            if os.path.splitext(self.list.GetString(i))[-1]=='.jpg':
                break
        if i<self.list.GetCount():
            index = i
        self.list.SetSelection(index)
        return self.list.GetStringSelection()

    #获得上一张图片
    def GetPreImage(self):
        index = self.list.GetSelection()
        i = index
        while i-1>0:
            i -= 1
            if os.path.splitext(self.list.GetString(i))[-1]=='.jpg':
                break
        if i>0:
            index = i
       
        self.list.SetSelection(index)
        return self.list.GetStringSelection()


class PBPicFrame(wx.Frame):

    max_width = 400
    max_height = 600

    def __init__(self, app):