【问题标题】:Convert Tkinter py file into EXE file将 Tkinter py 文件转换为 EXE 文件
【发布时间】:2017-06-30 11:13:27
【问题描述】:

我正在尝试使用 cx_freeze 将我的 tkinter 文件转换为 EXE,但我一直收到此错误 the error

希伯来语部分的翻译:找不到模块

我的安装文件代码是:

    import sys
from cx_Freeze import setup, Executable
import os

os.environ['TCL_LIBRARY'] = "C:\\Users\\royreznik\\AppData\\Local\\Programs\\Python\\Python36-32\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] =  "C:\\Users\\royreznik\\AppData\\Local\\Programs\\Python\\Python36-32\\tcl\\tk8.6"


build_exe_options = {"includes": ["tkinter"]}

base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(
    name = "simple_Tkinter",
    version = "0.1",
    description = "Sample cx_Freeze Tkinter script",
    options = {"build_exe": build_exe_options},
    executables = [Executable("tal1.py", base = base)])

我的主要文件是:

from tkinter import *
root = Tk()


Entry1 = Entry(root)
Entry2 = Entry(root)

Entry1.grid(row=0)
Entry2.grid(row=1)

Label1 = Label(root, text="null")
Label1.grid(row=4)

def funca():
    phrase = Entry1.get()
    words = phrase.split()
    wordCount = 0;
    for word in words:
        if word == Entry2.get():
            wordCount = wordCount+1
    Label1.configure(text=wordCount)

btn = Button(root, text="get Num",command=funca)
btn.grid(row=3)



root.mainloop()

有什么问题?

【问题讨论】:

  • 我建议你使用py2exe library

标签: python tkinter exe cx-freeze


【解决方案1】:

在 Python 目录的 DLLs 文件夹中,您将找到 tk86t.dlltcl86t.dll。您必须将它们与您要编译的 main.py 一起复制到 build 文件夹中。

然后您必须将这两个文件添加到您的setup.py 中的include_files 参数中。

现在,您的setup.py应该看起来像这样:

import os
from cx_Freeze import setup, Executable

os.environ['TCL_LIBRARY'] = 'c:/python36/tcl/tcl8.6'
os.environ['TK_LIBRARY'] = 'c:/python36/tcl/tk8.6'

buildOptions = dict(
    packages = [],
    excludes = [],
    include_files=['c:/python36/DLLs/tcl86t.dll', 'c:/python36/DLLs/tk86t.dll']
)

import sys
base = 'Win32GUI' if sys.platform=='win32' else None

executables = [
    Executable('editor.py', base=base)
]

setup(name='editor',
      version = '1.0',
      description = '',
      options = dict(build_exe = buildOptions),
      executables = executables)

当然,您可能必须调整目录路径才能使其正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-03
    • 2020-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 2019-02-09
    相关资源
    最近更新 更多