How do I add a “New” Python script option to the context menu?

自闭症网瘾萝莉.ら 提交于 2020-01-12 05:07:21

问题


I'm trying to add a context menu option for New -> Python Script on Windows 7. However, everything I've tried has failed.

The way that I thought it should work is below:

Add the following registry key:

[HKEY_CLASSES_ROOT\.py\ShellNew]
"FileName"="Template.py"

Null File version:

[HKEY_CLASSES_ROOT\.py\ShellNew]
"NullFile"=""

Optional registry key

[HKEY_CLASSES_ROOT\.py]
"PerceivedType"="text/plain"
@="Python Script"

Add the file to the Windows, ShellNew folder...

This does nothing, although I've done this before, and it worked with other file types. I'm unable to find anything for this anywhere, because they do everything I try for other file types.

What am I doing wrong?

EDIT: Python 2.7.8 or later has this option added during setup/installation.

Reference: MSDN Extending Shortcut Menus


回答1:


HKEY_CLASSES_ROOT\.py\PerceivedType="text" 

together with

HKEY_CLASSES_ROOT\.py\ShellNew\NullFile=""

works for me on Windows 7.

I have also set HKEY_CLASSES_ROOT\Python default value to "Python Script"


Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.py]
@="Python"
"Content Type"="text/x-python"
"Python"="Python"
"PerceivedType"="text"

[HKEY_CLASSES_ROOT\.py\ShellNew]
"NullFile"=""

[HKEY_CLASSES_ROOT\Python]
@="Python Script"



回答2:


I have found that the easiest way to do this is with the following method, which I have tested on my Windows 10 PC.

  1. Open Regedit
  2. Navigate to Computer\HKEY_CLASSES_ROOT.py
  3. Right click on the .py key > New > Key
  4. Name the new key "ShellNew"
  5. Inside the ShellNew key, add a new string value
  6. Name the string value "NullFile"
  7. Change the NullFile's value to 1
  8. That's it!

(note: this should work with all plain-text file formats)




回答3:


Use open++. It's easy to configure, and maybe it can do what you want.



来源:https://stackoverflow.com/questions/19758455/how-do-i-add-a-new-python-script-option-to-the-context-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!