使用cx_Freeze为Windows构建的python tkinter exe将不显示GUI [英] python tkinter exe built with cx_Freeze for windows won't show GUI

查看:106
本文介绍了使用cx_Freeze为Windows构建的python tkinter exe将不显示GUI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题已解决。
的问题是jaraco模块,我用于剪贴板操作,而是使用pyperclip。

PROBLEM SOLVED. the issue was with jaraco module, that i used for clipboard manipulation, i used pyperclip instead.

我用tkinter制作了一个python应用程序,可以正常工作,但是我想从中制作一个exe,以便它在Windows中易于使用。我为此使用了cx_Freeze库,它也可以正常工作,但并非总是如此。

I made a python app with tkinter that works fine, but I wanted to make an exe from it so it's user friendly in windows. I used cx_Freeze library for that, that works fine too, but not always.

使用cx_Freeze创建exe时,您可以指定基本参数,如果不指定将打开的参数2个窗口,cmd窗口和一个适用于您的应用程序的GUI窗口。为了摆脱cmd窗口,您可以将 Win32GUI指定为cx_Freeze的基本参数。

When creating the exe using cx_Freeze you can specify base parameter, if you give none that will open 2 windows, cmd window and a GUI window for your app. To get rid of the cmd window you can specify "Win32GUI" as base parameter for cx_Freeze.

这将忽略cmd窗口并仅打开GUI,这似乎在起作用, 但不总是。
有时打开exe文件将启动进程,但不会显示GUI。打开cmd并进入exe目录,然后从那里启动它会真正显示GUI并解决问题,直到您重新启动计算机(您可以在不使用cmd的情况下打开应用程序,直到重新启动为止)

This ignores the cmd window and just opens the GUI, it seems to be working, but not always. Sometimes opening the exe file will start the proccess but no GUI will show. Opening cmd and going to the directory of your exe and starting it from there will actually show the GUI and fix the problem untill you restart your pc (you can open the app without cmd with everything working untill restart)

似乎只要cmd窗口在您的内存中,GUI就会显示出来,否则不知道并且无法显示GUI。

It seems that as long as cmd window is in your ram, the GUI will show, otherwise it "doesn't know" and fails to show GUI.

代码可在此处找到:
https:/ /github.com/GrishaDev/ClipMagic

clip.py
是整个应用程序

clip.py is the entire app

setup.py
是cx_Freeze用来获取应用程序exe的文件,您可以在其中指定基本参数等。

setup.py is the file used with cx_Freeze to get exe of the app, that's where you specify base parameter and such.

最可能出现问题的代码段( setup.py ):

the piece of code where the problem most likely is (setup.py):

import sys
from cx_Freeze import setup, Executable
# import os
# os.environ['TCL_LIBRARY'] = "C:\\Users\\Grisha\\AppData\\Local\\Programs\\Python\\Python35\\tcl\\tcl8.6"
# os.environ['TK_LIBRARY'] = "C:\\Users\\Grisha\\AppData\\Local\\Programs\\Python\\Python35\\tcl\\tk8.6"
import os.path
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')

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

setup(name="clipmagic",
      version="1",
      description="Extended clipboard",
      options={'build_exe': {'includes': ["jaraco", "tkinter"], 'include_files':[
            os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
            os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
            'icon.ico',
         ]}},
      executables=[Executable("clip.py", base=base, icon='icon.ico')])

#"Win32GUI"

谢谢!

推荐答案

查看 README.md 在代码存储库中,您正在使用 cx_Freeze 的当前版本,即5.1.1。在此版本中,包含的模块位于构建目录的子目录 lib 中。手动添加的DLL显然也需要移动到那里。请参见此答案

Looking at the README.md in your code repository, you are using the current version of cx_Freeze, which is 5.1.1. In this version, the included modules are in a subdirectory lib of the build directory. The manually added DLLs apparently need to be moved there as well. See this answer.

尝试对以下内容进行以下更改:您的 setup.py 脚本:

Try to make the following change to your setup.py script:

options={'build_exe': {'includes': ["jaraco", "tkinter"], 'include_files':[
    (os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'), os.path.join('lib', 'tk86t.dll')),
    (os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'), os.path.join('lib', 'tcl86t.dll')),
    'icon.ico',
    ]}},

这篇关于使用cx_Freeze为Windows构建的python tkinter exe将不显示GUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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