image.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:pywal 作者: dylanaraps 项目源码 文件源码
def get_random_image(img_dir):
    """Pick a random image file from a directory."""
    current_wall = wallpaper.get()
    current_wall = os.path.basename(current_wall)

    file_types = (".png", ".jpg", ".jpeg", ".jpe", ".gif",
                  ".PNG", ".JPG", ".JPEG", ".JPE", ".GIF")

    images = [img for img in os.scandir(img_dir)
              if img.name.endswith(file_types) and img.name != current_wall]

    if not images:
        print("image: No new images found (nothing to do), exiting...")
        sys.exit(1)

    return os.path.join(img_dir, random.choice(images).name)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号