1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > python实现动态壁纸_用Python实现动态的切换桌面背景

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

时间:2021-07-11 16:09:27

相关推荐

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] + '\'')

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。