我目前正在使用具有以下代码的 python 脚本。它打开一个包含 JSON 文本的文件并从中确定一个值。
browseFiles()
def browseFiles():
global fileName
fileName = filedialog.askopenfilename(title = "Select a File", filetypes = (("All Files","*.*")))
# Open the File in Read Mode
fileFile = open(fileName, "r")
# Read the file
fileContent = fileFile.read()
# Render the JSON
fileJSON = json.loads(fileContent)
# Determine the ID
myID = fileJSON["key"]
# Update the Status
windowRoot.title(myID)
... remaining code
fileFile.close()
但是,每次都打开程序,然后导航到它不太方便。
Windows 在文件资源管理器中具有“打开方式”功能,我们可以在其中右键单击文件并使用 Word 等应用程序打开它。
如何在 Python 脚本中实现这一点?我是否应该考虑首先创建这个脚本的 .exe,如果是,那么哪个库最适合这个?(考虑到它是一个非常小且简单的实用程序)
一些可能不需要的额外信息:我将 Tkinter 用于 GUI。
(顺便说一句,如果这个问题已经存在于 StackOverFlow 或任何其他网站上,那么请评论该链接,而不是仅仅将其标记为重复。我尝试了很多搜索但找不到任何东西)
问候,维万。