python实现动态壁纸_用Python实现动态的切换桌面背景

#!/usr/bin/python#-*- coding: utf-8 -*-

importos, os.path, fnmatch, commands#壁纸图片所在的目录

wallpaper_path = '/usr/share/backgrounds'

#搜索所有可用的壁纸

avail_wallpapers =[]for file inos.listdir(wallpaper_path):if not os.path.isfile(wallpaper_path + '/' +file):continue

if not fnmatch.fnmatch(file, '*.jpg') and\not fnmatch.fnmatch(file, '*.png'):continueavail_wallpapers.append('file://' + wallpaper_path + '/' +file)if len(avail_wallpapers) ==0:

amonest@amonest-virtual-machine:~/python$ cat dynamic_wallpaper.py#!/usr/bin/python#-*- coding: utf-8 -*-

importos, os.path, fnmatch, commands#壁纸图片所在的目录

wallpaper_path = '/usr/share/backgrounds'

#搜索所有可用的壁纸

avail_wallpapers =[]for file inos.listdir(wallpaper_path):if not os.path.isfile(wallpaper_path + '/' +file):continue

if not fnmatch.fnmatch(file, '*.jpg') and\not fnmatch.fnmatch(file, '*.png'):continueavail_wallpapers.append('file://' + wallpaper_path + '/' +file)if len(avail_wallpapers) ==0:

exit#对所有可用的壁纸排序

avail_wallpapers.sort()#获取当前使用的壁纸

current_wallpaper = commands.getoutput('gsettings get org.gnome.desktop.background picture-uri').strip('\'')#计算下一张壁纸索引

try:

current_index=avail_wallpapers.index(current_wallpaper)except:

current_index= -1next_index= current_index + 1

if next_index >=len(avail_wallpapers):

next_index=0#设置下一张新壁纸

os.system('gsettings set org.gnome.desktop.background picture-uri \'' + avail_wallpapers[next_index] + '\'')

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值