python tkinter exe built with cx_Freeze for windows wont show GUI

2024/11/17 17:30:11

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

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.

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.

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)

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.

The code can be found here: https://github.com/GrishaDev/ClipMagic

clip.py is the entire app

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

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"

Thanks!

Answer

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.

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',]}},
https://en.xdnf.cn/q/118782.html

Related Q&A

lxml tree connection and properties

I have a .dtsx file so, I have multiple components with connections, so I need to extract component that have especific connection, but I can not handle that, example: <components><component r…

Python recursive function call with if statement

I have a question regarding function-calls using if-statements and recursion. I am a bit confused because python seems to jump into the if statements block even if my function returns "False"…

How can I list all 1st row values in an Excel spreadsheet using OpenPyXL?

Using the OpenPyXL module with Python 3.5, I was able to figure out how many columns there are in a spreadsheet with:In [1]: sheet.max_column Out [1]: 4Then I was able to list the values in each of the…

Using matplotlib on non-0 MPI rank causes QXcbConnection: Could not connect to display

I have written a program that uses mpi4py to do some job (making an array) in the node of rank 0 in the following code. Then it makes another array in the node of rank 1. Then I plot both the arrays. T…

ioerror errno 13 permission denied: C:\\pagefile.sys

Below is my code, what I am trying to achieve is walking through the OS generating a MD5 hash of every file the code is functional, however, I receive the error in the title "ioerror errno 13 perm…

How can PyUSB be understood? [closed]

Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…

Resize image in python without using resize() - nearest neighbor

For an assignment I want to resize a .jpg image with a python code, but without using the pil.image.resize() function or another similar function. I want to write the code myself but I cant figure out …

Concatenate two dataframes based on no of rows

I have two dataframes:a b c d e f 2 4 6 6 7 1 4 7 9 9 5 87 9 65 8 2Now I want to create a new dataframe like this:a b c d e f 2 4 6 6 7 1 4 7 9 9 5 8 That is, I only want the rows of the …

Having Problems with AzureChatOpenAI()

people. Im trying to use the AzureChatOpenAI(), but even if I put the right parameters, it doesnt work. Here it is: from langchain_core.messages import HumanMessage from langchain_openai import AzureCh…

Finding cycles in a dictionary

I have a dictionary which has values as:m = {1: 2, 7: 3, 2: 1, 4: 4, 5: 3, 6: 9}The required output should be cyclic values like 1:2 -> 2:1 = cycle, which both are present in dictionary. 4:4 is also…