使用cx_Freeze创建可执行文件后,始终出现“文件对话框”错误 [英] Keep getting a 'filedialog' error after creating executable with cx_Freeze

查看:92
本文介绍了使用cx_Freeze创建可执行文件后,始终出现“文件对话框”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用python脚本中的cx_Freeze创建可执行文件,并且看来tkinter模块的某些部分未加载到可执行文件中。脚本文件包含导入语句:

I am trying to create an executable using cx_Freeze from a python script and it appears that certain portions of the tkinter module are not getting loaded into the executable file. The script file contains the import statements:

from tkinter import *
from tkinter.filedialog import askopenfile, asksaveasfile
from tkinter.messagebox import *
import subprocess
import time

我的脚本中有一些类似以下的代码:

Within my script I have some code that looks like this:

f_outfile = filedialog.asksaveasfile(initialdir=r'c:\Program Files (x86)\LTC\LTSpiceIV')

当我从IDLE内部运行此脚本时外壳,它可以完美地工作。我使用如下所示的setup.py文件使用cx_Freeze创建可执行文件:

When I run this script from inside the IDLE shell, it works flawlessly. I create an executable file with cx_Freeze using a setup.py file that looks like this:

from cx_Freeze import *

setup(name="voltage_substate_GUI",
  version="0.1",
  description="test",
  executables=[Executable("voltage_substate_GUI.pyw")],
  )

创建可执行文件没有任何问题,但是当我运行可执行文件时,控制台窗口中显示错误

The executable is created without any problems, however when I run the executable I get an error in the console window that says

NameError: name 'filedialog is not defined'

但是,创建GUI的脚本的其余部分似乎工作正常,所有按钮和所有Entry都可以正常工作()项目等。

However the rest of the script, which creates a GUI, appears to work just fine ---- all the buttons work as well as all the Entry() items, etc.

对这个问题有任何想法吗?

Any thoughts on the problem?

谢谢!

推荐答案

由于某种原因,我不得不在冻结的脚本中显式导入'filedialog'和'messagebox'子模块。

For some reason, I had to import the 'filedialog' and 'messagebox' submodules explicitly in the script I was freezing.

import tkinter.filedialog as fdialog
import tkinter.messagebox as msgbox
import tkinter

标签,按钮,框架,条目等工作正常,谁知道必须以这种方式导入多少其他对象。希望这对某人有帮助。

While 'Label', 'Button', 'Frame', 'Entry', etc. worked fine, who knows how many others must be imported in that fashion. Hope this helps someone.

这篇关于使用cx_Freeze创建可执行文件后,始终出现“文件对话框”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆