国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Linux > 正文

Python創建、刪除桌面、啟動組快捷方式的例子分享

2019-10-26 18:40:27
字體:
來源:轉載
供稿:網友

一、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) 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 北海市| 工布江达县| 甘洛县| 安国市| 徐州市| 云龙县| 杭州市| 岳池县| 那坡县| 忻城县| 泾川县| 驻马店市| 承德县| 德令哈市| 吴川市| 府谷县| 舞阳县| 巩义市| 永定县| 宁德市| 呼图壁县| 张家川| 亚东县| 肥城市| 青田县| 修水县| 双鸭山市| 翁牛特旗| 新巴尔虎右旗| 梁平县| 红原县| 洛川县| 亳州市| 亚东县| 安泽县| 房山区| 科技| 紫阳县| 望江县| 岳普湖县| 靖边县|