zoukankan      html  css  js  c++  java
  • python小练习给右键菜单添加用chrome打开

    在open_chrome文件夹下有两个文件,一个是open_chrome.py,一个是setup.py

    open_chrome.py用来先注册表添加右键菜单项

    # -*- coding: utf-8 -*-
    #coding=utf-8
    #Python -V: Python 2.7
    #filename:open_chrome.py

    import _winreg
    import webbrowser

    def menu_reg():
    prog_name = 'open chrome' # 程序名称(即右键菜单中显示的名称)
    prog_path = r"D:\Download\GoogleChrome_Dev\App\Chrome\chrome.exe" # 程序路径(即可执行文件所在路径)
    # 打开名称为“HEKY_CLASSES_ROOT\*\shell”的键key
    key = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, r'*\\shell')
    # 为键key新建名称为prog_name的子键,
    # 并设置其数据为REG_SZ(字符串值)类型的prog_name((&I)表示指定快捷键为I)
    _winreg.SetValue(key, prog_name, _winreg.REG_SZ, prog_name + '(&I)')

    # 打开名称为prog_name的子键prog_key
    prog_key = _winreg.OpenKey(key, prog_name)
    # 为键prog_key新建名称为'command'的子键,
    # 并设置其数据为REG_SZ(字符串值)类型的prog_path + ' %1'
    _winreg.SetValue(prog_key, 'command', _winreg.REG_SZ, prog_path + ' %1')

    _winreg.CloseKey(prog_key) # 关闭键prog_key
    _winreg.CloseKey(key) # 关闭键key


    if __name__ == "__main__":
    menu_reg()

     在open_chrome文件夹下setup.py用来把open_chrome.py打包成open_chrome.exe(需要安装py2exe)

    # setup.py

    from distutils.core import setup

    import py2exe

    setup(console=["open_chrome.py"])

    运行命令为: python setup.py py2exe

    在dist文件下运行open_chrome.exe,右键点击一个文件可以看到open_chrome项。

  • 相关阅读:
    网络流二十四题之魔术球问题
    网络流二十四题之P2764 最小路径覆盖问题
    网络二十四题 之 P2756 飞行员配对方案问题
    网络流 之 dinic算法
    网络流 之 增广路
    中南
    2249: Altruistic Amphibians 01背包的应用 + lh的简单图论 图转树求lca
    今日训练 搜索
    AD-logon workstation
    Centos7-docker安装
  • 原文地址:https://www.cnblogs.com/lkprof/p/3113722.html
Copyright © 2011-2022 走看看