将Tkinter py文件转换为EXE文件 [英] Convert Tkinter py file into EXE file

查看:236
本文介绍了将Tkinter py文件转换为EXE文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

im尝试使用cx_freeze将tkinter文件转换为EXE,但是我一直都收到此错误
错误

im trying to convert my tkinter file into EXE using cx_freeze, but i got this error all the time the error

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

translation of the hebrew part: module didnt found

我的设置文件代码是:

    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()

出什么问题了?

推荐答案

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

In your Python directory's DLLs folder you will find tk86t.dll and tcl86t.dll. You have to copy them into the build folder with the main.py you want to compile.

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

Then you have to add these two files to the include_files parameter in your setup.py.

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

Now, your setup.pyshould look like something like this :

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)

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

Of course you may have to adapt the directories paths to make it work.

这篇关于将Tkinter py文件转换为EXE文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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