So I recently managed to convert a .py file into .exe but the problem is that the .exe file wont open properly. Basically what happens is the command prompt opens for a second and then shows some code for 1 milisecond and closes. I did manage to get a screenshot of what the command prompt says.This keeps happening when I try to open it but not with just that file, but every .py file I convert into .exe
I made a simple code to check if it was only like that for my previous code but its for every code that I make. I also used PyInstaller to convert the .py file into a .exe
import customtkinter as tk
import sys
import os
root = tk.CTk()
root.state('zoomed')
root.wm_title("Test File")
frame = tk.CTkFrame(master=root, height=300, width=600)
frame.pack_propagate(0)
frame.pack(pady=200)`
lbl = tk.CTkLabel(master=frame, text="I like chicken nuggets.", font=("Bahnschrift", 30))
lbl.pack(pady=120)
root.mainloop()
If something is unclear about my explanation, please ask. Im on Windows 11 and I use VS Code.
I asked for help on Discord but no luck. Im hoping somebody could help me here. I want my .exe file to open up like a charm and do its job.
I suggest using auto-py-to-exe since it's easier to use. To install type this:
pip install auto-py-to-exe
To run type this:
auto-py-to-exe
Then you'll see something like this:
Add the path to your script and you can change any setting you want
Then you'll need to add the path to your custontkinter package
Go to Additional Files -> Add Folder -> locate your python folder -> Lib -> site-packages -> customtkinter and add it to your exe
Scroll down and you'll see this button. Press it and your exe should work
Related
EDIT: I'm using the "random" library and the "os" library, could they be interfering with the file's execution?
Good morning, I'm creating a hangman game that runs all in the terminal, doesn't open any graphical window, I used pyinstaller to turn my .py file into an executable. When I run it through the command ./My_file it works normally, but if I try to run it by double clicking it doesn't open anything! Does anyone know how to solve?
I have made a simple “Hello World” app in python and turned it into a standalone exe file using pyinstaller. The problem is, the title bar of the console always shows the file path of the exe file. Is there any way to remove the filepath from the window? here is the image
Change the name of the console window in the code
import os
os.system('title MyTitleHere')
If you are using a GUI as part of your program, you can set the title (and icon) there, but for a console-based output, this is the best option. There is no .spec file option to do this.
I used below code to make execute of my program:
from distutils. core import *
import py2exe,sys,os
sys.argv.append('py2exe')
setup(options={'py2exe':{bundle_files':1,'compressed':True,'includes':["Tkinter",]}}'windows=['trial.py'],zipfile=None,)
It is creating single file .exe, but not executing.
same code with bundle_file 3 (without single file) is working fine.
trial.py:
import Tkinter
Tkinter.Tk()
mainloop()
Please help me to create a single .exe file for GUI program
PyInstaller is a much easier option that can be used from the console. Just pip install pyinstaller, enter your program's directory, and pyinstaller yourscript.py.
I am confused that you say trial.py is working fine when I get an error on my machine. mainloop() needs to be replaced by Tkinter.mainloop().
I am running Windows 7 and have Python 3.3 64 bit installed. I seem to have a problem importing the tkinter module, I can import it fine through the python IDLE and it will work, but when I save the .py file and double click it, a cmd window will open and say:
Traceback (most recent call last):
File "C:Users\username\Desktop\g.py", line 3, in <module>
from tkinter import *
ImportError: No module named tkinter
I have tried the following:
I have tried import tkinter, from tkinter import *, and import tkinter as tk and they don't seem to work when the .py file is opened directly (double clicked).
I also double checked the path variable and it was set correctly.
I uninstalled python and reinstalled it.
I checked to see if tkinter is in the folder C:\Python33\Lib\, and it is.
I do have a mainloop() in my program.
In my program, tkinter is all lowercase.
I tried a lot of solutions online from other posts, and they didn't work for me.
The top of my code is:
import sys
from tkinter import *
I don't know what I am missing, any suggestions?
I'm going to make this an answer then for anybody in the future.
The problem is that Windows is currently set to run all .py files with a different executable (probably a Python 2.x one) To fix the problem, follow these steps:
Right-click a .py file.
In the menu that pops up, go to Open with.
In the submenu that pops up, click on Choose default program...
A window will then appear. In this window, click on the Browse... button.
Then, go find the Python execuatble. It should be at C:\Python33\python3.3.exe. (There might be multiple pythonX.exe files. If one doesn't work, try another.)
Once you select it, click Open.
If done correctly, this procedure will manually reset the default executable for .py files to be the Python 3.x one. Meaning, your script should run fine now.
This is actually a simple solution.
You have:
from tkinter import *
You need:
from Tkinter import *
Capitalization is very specific!!!
I am trying to open a file through python that once it is open takes you to a GUI. The link works fine when i just click on it and python seems to locate the file and open it, but the GUI doesn't appear. Please help. This is whay i have been using.
import subprocess
subprocess.Popen("C:/full/path")
I get no track back errors, but the GUI doesn't appear. Thoughts of how I can get it to appear, or what the problem might be?
Thanks
The file you're trying to 'start' is a cmd script. Use this code:
subprocess.Popen("cmd.exe /k C:\full\path\to\file.cmd")
.cmd files are not executable by themselves - you need to invoke cmd.exe to execute them. This is also what windows does when you double-click the file on the desktop.