Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在打开文件时在cxFreeze编译的python可执行文件中打开自定义文件类型_Python_Windows_Tkinter_Cx Freeze_Rubiks Cube - Fatal编程技术网

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

在打开文件时在cxFreeze编译的python可执行文件中打开自定义文件类型,python,windows,tkinter,cx-freeze,rubiks-cube,Python,Windows,Tkinter,Cx Freeze,Rubiks Cube,我正在使用cx_Freeze用python编译一个Rubiks立方体模拟器;它使用tkinter。 我希望用户能够将您在中心看到的二维表示的布局保存到.cube文件中,并能够从程序本身打开以前的.cube文件 但是,我还希望用户能够从Explorer中打开.cube文件,并让程序启动时显示用户打开的.cube文件的内容 在做了一些研究之后,我想我需要访问“运行时环境”或其他什么东西,但除此之外我完全不知道。UPDATE 我使用argparse模块解决了这个问题。基于这样一个事实,每次资源管理器

我正在使用cx_Freeze用python编译一个Rubiks立方体模拟器;它使用tkinter。

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

但是,我还希望用户能够从Explorer中打开.cube文件,并让程序启动时显示用户打开的.cube文件的内容

在做了一些研究之后,我想我需要访问“运行时环境”或其他什么东西,但除此之外我完全不知道。

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

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文件的图标