How to make a user friendly start of a Python program? - python

I have a Python program (GUI application). I can run this program from the command prompt on Windows (command line on Linux). But it can be too complicated for users. Is there an easy way to initiate a start of the program with a click (double click) on a pictogram (a small image on the desktop)?

Linux:
I am not sure, which linux distro and desktop you use but for gnome I create such files on desktop e.. create a myapp.desktop and put in on desktop
[Desktop Entry]
Version=1.0
Encoding=UTF-8
Name=MyApp
Type=Application
Exec=python /home/anushri/display.anurag/xxx.py
TryExec=
Icon=/usr/share/pixmaps/gnome-qeye.png
X-GNOME-DocPath=
Terminal=false
Name[en_IN]=MyApp
GenericName[en_IN]=MyApp
Comment[en_IN]=MyApp
GenericName=MyApp
Comment=MyApp
Windows:
Right-click an open area on the desktop, point to New, and then click Shortcut, type the command line to start you program, Type a name for the shortcut

I'm not sure if I understood the question well, but if you just need a way to simulate a command line input with a simply clickable icon, just create a simple .bat file (assuming windows) on the desktop, as a new text file containing something like
C:\[Pythonpath]\python C:\[MyPythonAppPath]\myapp.py
See http://en.wikipedia.org/wiki/Batch_file for more info.

Use py2exe to make an exe and just to make it more 'user friendly' use Inno set up (www.jrsoftware.org/isinfo.php ) along with IStools to build up an installer which would integrate the GUI with sound, widgets, other elements etc and users who do not have python etc installed in their systems can also play your GUI perfectly fine !
By the way what GUI are you using ? pygame, tk, wx, PyQt ...etc ?

What I've done in the past is use py2exe to create an executable from my python script. That embeds the interpreter and the source inside an EXE, that way it works just like a native executable and you don't have to have the users install python or anything complicated.

Related

Is it possible to package a python application with its separate terminal?

I would like to have an executable (Windows, MacOS, Linux) of my program that will have its own terminal window where users will be able to type in. I don't want to have the user install modules or anything except this executable. You could say that the UI of my program would be a terminal window. Is it possible and with what?
I basically want the GUI of my app to be a terminal window.
To create a command-line interface for your program you'll likely want to use something like argparse, which is in the standard Python library. There are many other feature-rich command-line interface modules (e.g., click) you could try to use instead. You can design command-line interactions for your users including input and output, menus, etc.
Once you've built your application, a good choice to make it portable is the PyInstaller module. If you set the --onefile option when invoking it, it will generate a single .exe file which can be easily shared with users. If you also set the --console option when invoking PyInstaller, then your Python .exe application will interface with stdin/stdout. On Windows, this would be a cmd window.
If a user invokes your .exe via the GUI (e.g., a double-click on its icon), a Windows CMD window will be opened. If you want that window to stay open, however, you will need to create your application with some kind of "infinite"/"captive" design that never finishes executing until the user explicitly quits.
If the user instead runs the .exe from a Windows CMD terminal that is already open, then that window will always stay open.
I suspect you're looking for curses, or UniCurses if you're stuck with Microsoft Windows.
Many terminal emulators will allow you to start them up with a command line option that specifies a command to run in that emulator instead of your default shell.

How-to Launch Android Python Script via Shortcut on Homescreen

I've scoured the interwebs and couldn't find anything with python, android, and "shortcut" or "home-screen" to appear on the same page. I have pydroid3 installed, working great. I'd like to have a shortcut (ideally on the home-screen) that I can tap once and have it run without opening the IDE for editing.
Making a shortcut to the file, or opening a source file in the file manager will at best just open it in the pydroid3 IDE, at worst state "this file type is not supported."
At the beginning of the script, I have tried putting "#!/user/data/../pydroid_dir/python", but alas the OS doesn't realize I mean to run it directly in the python interpreter. Any solutions or alternative lines of thinking are appreciated!
EDIT
I'm running an unrooted android 9 PIE. I wanted to provide some more details but not quite a solution for any readers. Check out related question: How to create a homescreen shortcut to launch a shell script?. Closest I got was trying SManager which allows you to create a homescreen shortcut to a shell script. Your shell script could be hardcoded to call python on your script:
/path/to/python /path/to/python/script
Unfortunately, if you're phone is not rooted, you may not have permission to execute whatever version of python you're calling outside of the context of the app it was installed for. Also, you have to ensure that your shell and python scripts reside in an appropriate place for execution. If your phone is rooted, SManager seems to have options to let you run the script as root.
pydroid3 allows me to run scripts residing on my internal storage as well as lets them read and write files at that location. That's why I was hoping that there was a pydroid way to create a shortcut (or an alternative python app that does this) since it has appropriate privileges.
QPython OL lets you create home screen shortcuts to python scripts on Android. First tap on the 'Q' icon at the top of the main screen (it took me a while to realise this was a button), then long-press on the script you want. This should give you a prompt to create a shortcut, as in the screenshots below.
QPython 3L also claims to have similar functionality when you long-press a script in its 'Programs' section. At time of writing (Jun 20) this seems to be broken.
I've not tried Pydroid myself, but haven't come across anything claiming it could create script shortcuts either.
You can use Termux:Widget as a command line to execute a python script. In Termux you can not create GUI with tkinter. You have to launch X-Server with VNC Mobile client. The widget is like a small shell prompt.

Pinning python application running through Python interpreter

I have an application I run using pythonw.exe. I just click on my .pyw file and it runs. It's using Qt and I have set up an icon that both shows in the window and in the taskbar.
However when I try to pin it, it pins the python IDLE incorrectly instead of the application itself. It makes some sense since it is a python file run from pythonw.exe. Example below:
So how do I proceed to run the application the right way so I can pin it to the taskbar?
As eryksun said you need a shortcut with pythonw.exe "Path to pyw file" in target.

I have a Python program that the customer would like to access as a double clickable desktop icon on Windows 8. How do I do this? 8

I have a program called ftpgrab.py. At the command prompt to run it I type:
c:\path\to\python\dir\python.exe ftpgrab.py
Is there a way on Windows 8 to create an icon which I can double-click to run this?
You can either create a batch file that will launch the program, or use something like pyinstaller to transform your script into an executable that can be run directly.
create a file named foo.bat;
copy your command to that file and save it;
double click foo.bat...
Assuming that you used one of the standard installers for python on windows, .py is already registered and it should just work. Copy it to your desktop and double-click. A console running the program should appear and run as normal. Its still a console app - the the customer wants a gui app, that's a different story.
btw, you shouldn't even have to type c:\path\to\python\dir\python.exe ftpgrab.py, just a plain ftpgrab.py or ftpgrab should do.

How to start IDLE (Python editor) without using the shortcut on Windows Vista?

I'm trying to teach Komodo to fire up IDLE when I hit the right keystrokes. I can use the exact path of the shortcut in start menu in the Windows Explorer location bar to launch IDLE so I was hoping Komodo would be able to use it as well. But, giving this path to Komodo causes it to say that 1 is returned. This appears to be a failure as IDLE doesn't start up.
I thought I'd avoid the shortcut and just use the exact path. I go to the start menu, find the shortcut for IDLE, right click to look at the properties. The target is grayed out, but says "Python 2.5.2". The "Start in" is set to, "C:\Python25\". The "Open File Location" button is also grayed out.
How do I find out where this shortcut is really pointing? I have tried starting python.exe and pythonw.exe both in C:\Python25, but neither starts up IDLE.
There's a file called idle.py in your Python installation directory in Lib\idlelib\idle.py.
If you run that file with Python, then IDLE should start.
c:\Python25\pythonw.exe c:\Python25\Lib\idlelib\idle.py
In Python 3.2.2, I found \Python32\Lib\idlelib\idle.bat which was useful because it would let me open python files supplied as args in IDLE.
Here's another path you can use. I'm not sure if this is part of the standard distribution or if the file is automatically created on first use of the IDLE.
C:\Python25\Lib\idlelib\idle.pyw
If you just have a Python shell running, type:
import idlelib.PyShell
idlelib.PyShell.main()
there is a .bat script to start it (python 2.7).
c:\Python27\Lib\idlelib\idle.bat
Python installation folder > Lib > idlelib > idle.pyw
Double click on it and you're good to go.
You can also assign hotkeys to Windows shortcuts directly (at least in Windows 95 you could, I haven't checked again since then, but I think the option should be still there ^_^).
The idle shortcut is an "Advertised Shortcut" which breaks certain features like the "find target" button. Google for more info.
You can view the link with a hex editor or download LNK Parser to see where it points to.
In my case it runs:
..\..\..\..\..\Python27\pythonw.exe "C:\Python27\Lib\idlelib\idle.pyw"
I setup a short cut (using windows) and set the target to
C:\Python36\pythonw.exe c:/python36/Lib/idlelib/idle.py
works great
Also found this works
with open('FILE.py') as f:
exec(f.read())
Another option for Windows that will automatically use the most recent version of Python installed, and also doesn't make you look for the installation path:
Target: pyw -m idlelib
Start in: Wherever you want
I got a shortcut for Idle (Python GUI).
Click on Window icon at the bottom left or use Window Key (only Python 2), you will see Idle (Python GUI) icon
Right click on the icon then more
Open File Location
A new window will appears, and you will see the shortcut of Idle (Python GUI)
Right click, hold down and pull out to desktop to create a shortcut of Python GUI on desktop.
Python installation folder > Lib > idlelib > idle.pyw
send a shortcut to desktop.
From the desktop shortcut you can add it to taskbar too for quickaccess.
Hope this helps.
If it's installed on windows 10 without changing default location, it seem it is in "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0x64__{BUNCHOFRANDOMSTRINGS}"
and you won't be able to open it.
Good luck finding how open .py by default with idle.

Categories