python saving .pyw to desktop after running a program - python

from Tkinter import *
import tkMessageBox
from test2_new import *
When I run this, python is saving a .pyw file of test2_new to the deskop. Why is this happening and how do i fix this? Thank you!

A pyw file is a windows specific format that is generated for GUi scripts. It causes windows to open the script directly in a window instead of launching a console. Most likely you are calling your script from the user desktop location. Try changing directories to your script location. Also if you are double click launching your py then it could also be defaulting to the desktop. Move that pyw to your script location and run that pyw directly.

Related

Pyinstaller Mac App not running when clicked on in finder

I have created a python script that I am attempting to turn into an application on mac so that I do not have to alway open the terminal. I am using Tkinter to create a window that the script runs on.
I run pyinstaller --onefile -w -i "Icon Name" "myapp.py" and I get the Dist folder with both a unix script and a macOS application. Running the Unix Script works perfectly fine, however when I try and run the app it will breifly blink in the taskbar and then dissapear without doing anything. running open myapp in the terminal opens it fine, its just when I double click on it.
I have tried looking it up and PyInstaller App not opening on Mac leads me to this github thread https://github.com/pyinstaller/pyinstaller/issues/3753. I tried following along however when I get to the hook-_tkinter.py file mine is only 30 lines of code and looks like this:
import sys
from PyInstaller import compat
from PyInstaller.utils.hooks import logger
from PyInstaller.utils.hooks.tcl_tk import collect_tcl_tk_files
def hook(hook_api):
# Use a hook-function to get the module's attr:`__file__` easily.
"""
Freeze all external Tcl/Tk data files if this is a supported platform *or* log a non-fatal error otherwise.
"""
if compat.is_win or compat.is_darwin or compat.is_unix:
# collect_tcl_tk_files() returns a Tree, so we need to store it into `hook_api.datas` in order to prevent
# `building.imphook.format_binaries_and_datas` from crashing with "too many values to unpack".
hook_api.add_datas(collect_tcl_tk_files(hook_api.__file__))
else:
logger.error("... skipping Tcl/Tk handling on unsupported platform %s",
It does not have the specific lines that the thread is showing I need to edit. I should also note that I found the file in /opt/homebrew/lib/python3.10/site-packages/PyInstaller/hooks/hook-_tkinter.py instead of where the thread is pointing to. I cannot find this file there.
I also read somewhere (I forget where exactly) that I need TCL and tkinter installed which I thought I did already cause it comes with python. trying to find somewhere to download tcl brought me to activetcl but I am unsure how to install that on my computer so I am not sure if that is the solution or not because I cannot get it working.
Sorry for the long question but would anyone be able to assist me in getting this working?

tkinter GUI doesn't work when clicking .pyw

I have a piece of code that does two things: writes a .txt file to my current path and runs a module (which I can't see contents of as the files are all .pyc) which ultimately opens a tkinter GUI.
Here is the code:
import os.path
from tkinter import messagebox as msg
if not os.path.isfile('FAST Locked.txt'):
FASTlck = open('FAST Locked.txt', 'w+')
FASTlck.write('Locked')
FASTlck.close()
import pyFiles.FAST
os.remove('FAST Locked.txt')
else:
msg.showerror('FAST Locked', 'FAST is open by another user.\n' +\
'Please try again later')
exit()
When I run this code from an editor (IDLE or Spyder), it works perfectly. When I double click the .pyw file it only creates the .txt, I do not get the GUI. If I click the .pyw with the .txt file present, I DO get the error message. This makes me think it's something to do with the files inside this FAST module.
I'm running Python 3.7, recently had Anaconda installed on my work machine, previously they just ran Python 3.7 and used IDLE (every other work machine still does this, the code works fine). This makes me wonder if having conda/Spyder installed has messed it up?
Not sure which problem is more likely, and have no idea where to start as I'm relatively new to Python and all this code was written by someone else who's gone.

(Windows 10 64 bits) Py to Exe Error Python 3.8 (Pyinstaller, cx_Freeze)

Hi I'am a new python user please excuse my python basic level.
I have to update 26/10/2020 the Title to Windows 10 64bits, do to the fact that I have done the downgrade to 3.7 and the error is the same. The EXE file just blinks and closes.
I simplify the code to just the screen, using only the frame, and the same result, EXE just blinks and closes.
I think that the error is related to Pyinstaller and Windows 10 64 bits problems.
I am trying to create an EXE file from Py using Pyhton 3.8 unsuccessfully, using pyinstaller and/or cx_Freeze getting the same errors.
Several errors related to the .png, .ico access and even deleting this from the code, a simple screen with a frame does not open.
Please somebody can help me to solve this.
This is the code, I need to create onefile .exe using .PNG as Background and .ICO on the screen not only as .exe file icon.
from tkinter import *
root=Tk()
#set windows size
root.resizable(width=False, height=False)
root.geometry("925x722")
#set title
root.title("SOFT1)")
#frame 1
f1=Frame(root, width=345,height=475,bg="light
grey",highlightbackground="black",highlightthickness=4)
f1.place(x=20,y=235)
#set a image as BG
Logo=PhotoImage(file="fileIMG.png")
lab6=Label(root, image=Logo)
lab6.place(x=0, y=0)
Currently python 3.8 isn't supported by pyinstaller. I believe cx_Freeze does, but if you don't need any specific feature from python 3.8 then I would downgrade to python 3.7 and try using pyinstaller again. Simpler that way.
There aren't any specific errors for me to base my answer off of, but I'll show you my usual approach to fixing pyinstaller issues. First, I would run the pyinstaller command with the option --debug=all. By using this option, you can see all that goes on behind the scenes when you try and run your program. Then try running the .exe file from the command line, and redirect standard error to a text file:
>your_program_here.exe 2> error.txt
If you look inside error.txt, you should see a lot of information. The most important thing to look for is a program trace-back. It's the same kind of trace-back you'll see when there's an error in the python program you're running. the trace-back will show you which line in your code is raising an error, which is usually the culprit of why your .exe won't work.
Looking from your code, I would try using absolute file paths to open your images. Right now you have it so Pet_toolShare.png is opened from the same folder that your python file
is run from. Pyinstaller places the .exe in the "dist" folder so it wouldn't be able to access any files from outside of it unless you place the .exe in the same folder as your images.

Set tkinter filedialog to open only executable files

Is there a way to set the tkinter filedialog filetypes attribute to open executable files?
I've been using:
filedialog.askopenfilename(filetypes=[("Applications", "*.exe")],)
but it only opens .exe files, not all types of executable files (eg. .APP).
I could add more attributes to filetypes, but it will not work properly on Linux, where any file can be executed, as long as it has the execute permissions (see here).
How can I set thinter's filedialog to only open any kind of executable file?
I am using Python 3.6.4 on Windows 10 and Python 3.5 on Ubuntu 16.
Any help would be greatly appreciated
There's nothing you can do by using the standard dialogs. Tkinter doesn't support listing files by attributes other than their extensions. You'll have to create your own file selection dialog if you want this feature.

How can I make my GUI program(tkinter) work on computers with no python installed such that no console window appears?

Here's what I have done so far:
-I made a desktop search program/GUI using python and tkinter.
-Then I used py2exe to convert it to an exe.
-Now the software perfectly works on a machine(windows) without python installed, but the problem is that a creepy black window just appears along with the GUI when the .exe is opened.
Is there any way to make it look less creepy to an end user?
Change the file extension from .py to .pyw
(You must have Python installed for this to work.)
Duplicate:
Hide console window with Tkinter and cx_Freeze
Before converting your file to an exe, change the file extension (by renaming the file) from .py to .pyw.
'.py' files open with the console, whereas '.pyw' files open with no console window.

Categories