一、Python创桌面建快捷方式的2个例子
例子一:
复制代码 代码如下:
import os
import pythoncom
from win32com.shell import shell
from win32com.shell import shellcon
def createDesktopLnk(filename,lnkname):
shortcut = pythoncom.CoCreateInstance(
shell.CLSID_ShellLink, None,
pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
shortcut.SetPath(filename)
if os.path.splitext(lnkname)[-1] != '.lnk':
lnkname += ".lnk"
# get desktop path
desktopPath = shell.SHGetPathFromIDList(shell.SHGetSpecialFolderLocation(0,shellcon.CSIDL_DESKTOP))
lnkname = os.path.join(desktopPath,lnkname)
shortcut.QueryInterface(pythoncom.IID_IPersistFile).Save(lnkname,0)
if __name__ == '__main__':
createDesktopLnk(u"C:\Python27\python.exe","MyPython")
例子二:
首先得安装 ActiveState ActivePython . 因为这个中带了 winshell 库
复制代码 代码如下:
from os import path
import winshell
#----------------------------------------------------------------------
def create_shortcut_to_desktop(target,title):
"""Create shortcut to desktop"""
s = path.basename(target)
fname = path.splitext(s)[0]
winshell.CreateShortcut(
Path = path.join(winshell.desktop(), fname + '.lnk'),
Target = target,
Icon=(target, 0),
Description=title)
注:不支持win64
二、使用winshell模块创建、删除桌面、启动组快捷方式
当写好一个应用并发行的时候,我们希望在用户的桌面上建立快捷方式方便用户操作,winshell模块提供了我们需要的功能
下面这个函数将创建程序自身的快捷方式到桌面:
复制代码 代码如下:
from os import path
import winshell
def create_shortcut_to_desktop():
target = argv[0]
title = '我的快捷方式'
s = path.basename(target)
fname = path.splitext(s)[0]
winshell.CreateShortcut(
Path = path.join(winshell.desktop(), fname + '.lnk'),
Target = target,
Icon=(target, 0),
Description=title)
下面这个函数实现将本程序的快捷方式从桌面删除:
复制代码 代码如下:
def delete_shortcut_from_startup():
target = argv[0]
s = path.basename(target)
fname = path.splitext(s)[0]
delfile = path.join(winshell.startup(), fname + '.lnk')
winshell.delete_file(delfile)
下面这个函数实现了建立快捷方式到启动组:
复制代码 代码如下:
from os import path
import winshell
def create_shortcut_to_startup():
target = argv[0]
title = '我的快捷方式'
s = path.basename(target)
fname = path.splitext(s)[0]
winshell.CreateShortcut(
Path = path.join(winshell.startup(),
fname + '.lnk'),
Target = target,
Icon=(target, 0),
Description=title)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
- 刘德华.1999-人间爱【艺能动音】【WAV+CUE】
- 《蛋仔派对》敲锣猴子乔利皮肤图鉴
- 《蛋仔派对》二师兄皮肤图鉴
- 《蛋仔派对》发条鹦鹉巴洛皮肤图鉴
- 沈文程1988-畅销曲精华[爱莉亚][WAV+CUE]
- Brahms-ViolinConcerto,C.Schumann-3Romances-Batiashvili(2013)[96-24]
- Tchaikovsky-SymphonyNo.6-Nezet-Seguin,LisaBatiashvili(2014)[96-24].
- 《鸦卫奇旅》自定义是不是解锁不了难度
- 《海贼王赏金猎人》配置要求一览
- 《狗钩宇宙狗狗》联机失败解决方法
- 两款《宝可梦》国行版发售!售价299元 还有新外设
- 《塞尔达》新作常规通关20小时 全收集需30小时
- 腾讯Switch开启假日折扣!多款国产游戏迎史低
- 群星.1998-在那一年2CD【宝丽金】【WAV+CUE】
- 黄征.2012-征爱·拾力【乐华娱乐】【FLAC分轨】