在 cx_Freeze 中打开自定义文件类型在打开文件时编译 python 可执行文件

Opening custom file types in cxFreeze compiled python executable on opening file

我正在使用cx_Freeze在python中编译一个魔方模拟器;它使用 tkinter.

我希望用户能够将您在中心看到的二维表示的布局保存到 .cube 文件中,并能够从程序本身打开以前的 .cube 文件。

但是,我也希望用户能够从资源管理器中打开 .cube 文件,并让程序启动时显示用户打开的 .cube 文件的内容。

经过一些研究,我想我需要访问 "Runtime Environment" 或其他东西 - 但除此之外我完全不知道。

更新

我使用 argparse 模块解决了这个问题。基于每次资源管理器打开一个文件时,它都会使用文件目录的参数调用应用程序这一事实,我所要做的就是添加一个可选参数来捕获这些数据。

import argparse
parser=argparse.ArgumentParser()
parser.add_argument("cubefile",nargs="?",default=False)
#'nargs="?"' makes the argument optional
#-meaning an error will not be thrown if no file is parsed on execution
args=parser.parse_args()
if args.universefile != False:
    init_defaultcube = cubetools.getCubeFromCubeFileDir(args.universefile)
    #cubetools is my class and getCubeFromCubeFileDir just interprets the text in the file

但是,因为这个参数改变了 exe 的工作目录,而我的 GUI 图像引用是相对的,我不得不使用
重置当前目录 os.chdir(os.path.dirname(os.path.abspath(sys.executable)))
我现在正致力于在初始化时修改注册表以设置 .cube 文件的默认应用程序和图标。