Reputation: 110969
Python works on multiple platforms and can be used for desktop and web applications, thus I conclude that there is some way to compile it into an executable for Mac, Windows and Linux.
The problem being I have no idea where to start or how to write a GUI with it, can anybody shed some light on this and point me in the right direction please?
Upvotes: 314
Views: 238022
Reputation: 1
You could create and compile a C++ script which executes your python script. This would be more difficult than the above suggestions but would definitely be worth looking into as It'll make you return to Python with more confidence and possibly even a deeper understanding of how It all works.
Upvotes: 0
Reputation: 25052
First you will need some GUI library with Python bindings and then (if you want) some program that will convert your python scripts into standalone executables.
Of course, there are many, but the most popular that I've seen in wild are:
De-facto standard GUI library for python, free for commercial projects.
Popular, and free for commercial projects.
The former is not free for commercial projects. The latter is less mature, but can be used for free.
Qt itself supposedly supports
Android
andiOS
as well, but achiving same with it's bindings should be tricky.
Supposedly supports
Android
andiOS
as well.
Note that users of
WxWidgets
(henceWxPython
users), often need to useWxQt
as well, becauseWxWidgets
's own GUI is not yet atQt
's level (at time of writting).
Complete list is at http://wiki.python.org/moin/GuiProgramming
For all platforms:
PyQt
)For Windows:
For Linux:
For MacOS:
Upvotes: 318
Reputation: 23443
# I'd use tkinter for python 3
import tkinter
tk = tkinter.Tk()
tk.geometry("400x300+500+300")
l = Label(tk,text="")
l.pack()
e = Entry(tk)
e.pack()
def click():
e['text'] = 'You clicked the button'
b = Button(tk,text="Click me",command=click)
b.pack()
tk.mainloop()
# After this I would you py2exe
# search for the use of this module on stakoverflow
# otherwise I could edit this to let you know how to do it
with this code:
from distutils.core import setup
import py2exe
setup(console=['l4h.py'])
**
pip install pyinstaller
**
pyinstaller file.py
**
Read this post to make an exe on windows with pyinstaller the proper way and with one file and images in it https://pythonprogramming.altervista.org/auto-py-to-exe-only-one-file-with-images-for-our-python-apps/
Upvotes: 2
Reputation: 110
There's three things you could do:
The first thing is to find a GUI Designer that can launch its code as standalone applications like .exe files. I use a version of MatDeck (for people using GUI Designers I recommend MD Python Designer) as I believe(I use another version so I'm not too sure.) it allows me to convert the code to a standalone applications and by having it as such, there is no need to install the software on every PC that's going to run the program.
The second option is partially bypassing the problem, launch the GUI as a web page. This would give you the most compatibility as most if not all OS can utilize it. Once again, you would need a GUI Designer that can convert its components into a web compatible format, I've done it once and I used the same version of MatDeck(Visionary Deck), I would not recommend MD Python Designer this time as I don't know if it can turn its GUIs into websites using web assembly whereas Visionary Deck I've tried and tested. As with all things there are most likely other software this is just one I use frequently because I work a lot with Mathematics and Physics.
The third option is also kind of bypassing the problem but do it in Tkinter and just ensure you have a Python IDE or just plain old Python and run the code, this will launch the GUI. This is a good solution and maybe the simplest but I wouldn't class it as the shortest or the best. If you only plan to switch between a few operating systems and computers this will probably be your best bet.
Upvotes: 1
Reputation: 3768
!!! KIVY !!!
I was amazed seeing that no one mentioned Kivy!!!
I have once done a project using Tkinter, although they do advocate that it has improved a lot, it still gives me a feel of windows 98, so I switched to Kivy.
I have been following a tutorial series if it helps...
Just to give an idea of how kivy looks, see this (The project I am working on):
And I have been working on it for barely a week now ! The benefits for Kivy you ask? Check this
The reason why I chose this is, its look and that it can be used in mobile as well.
Upvotes: 2
Reputation: 5754
PySimpleGUI wraps tkinter and works on Python 3 and 2.7. It also runs on Qt, WxPython and in a web browser, using the same source code for all platforms.
You can make custom GUIs that utilize all of the same widgets that you find in tkinter (sliders, checkboxes, radio buttons, ...). The code tends to be very compact and readable.
#!/usr/bin/env python
import sys
if sys.version_info[0] >= 3:
import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
layout = [[ sg.Text('My Window') ],
[ sg.Button('OK')]]
window = sg.Window('My window').Layout(layout)
button, value = window.Read()
As explained in the PySimpleGUI Documentation, to build the .EXE file you run:
pyinstaller -wF MyGUIProgram.py
Upvotes: 3
Reputation: 3628
You can use appJar
for basic GUI development.
from appJar import gui
num=1
def myfcn(btnName):
global num
num +=1
win.setLabel("mylabel", num)
win = gui('Test')
win.addButtons(["Set"], [myfcn])
win.addLabel("mylabel", "Press the Button")
win.go()
See documentation at appJar site.
Installation is made with pip install appjar
from command line.
Upvotes: 1
Reputation: 7945
Another system (not mentioned in the accepted answer yet) is PyInstaller, which worked for a PyQt project of mine when py2exe would not. I found it easier to use.
Pyinstaller is based on Gordon McMillan's Python Installer. Which is no longer available.
Upvotes: 61
Reputation: 410
There's also PyGTK, which is basically a Python wrapper for the Gnome Toolkit. I've found it easier to wrap my mind around than Tkinter, coming from pretty much no knowledge of GUI programming previously. It works pretty well and has some good tutorials. Unfortunately there isn't an installer for Python 2.6 for Windows yet, and may not be for a while.
Upvotes: 12
Reputation: 15968
For the GUI itself:
PyQT is pretty much the reference.
Another way to develop a rapid user interface is to write a web app, have it run locally and display the app in the browser.
Plus, if you go for the Tkinter option suggested by lubos hasko you may want to try portablepy to have your app run on Windows environment without Python.
Upvotes: 6
Reputation: 22984
I'm not sure that this is the best way to do it, but when I'm deploying Ruby GUI apps (not Python, but has the same "problem" as far as .exe's are concerned) on Windows, I just write a short launcher in C# that calls on my main script. It compiles to an executable, and I then have an application executable.
Upvotes: 4
Reputation: 1762
An alternative tool to py2exe is bbfreeze which generates executables for windows and linux. It's newer than py2exe and handles eggs quite well. I've found it magically works better without configuration for a wide variety of applications.
Upvotes: 16
Reputation: 35609
Since python is installed on nearly every non-Windows OS by default now, the only thing you really need to make sure of is that all of the non-standard libraries you use are installed.
Having said that, it is possible to build executables that include the python interpreter, and any libraries you use. This is likely to create a large executable, however.
MacOS X even includes support in the Xcode IDE for creating full standalone GUI apps. These can be run by any user running OS X.
Upvotes: 6
Reputation: 21545
You don't need to compile python for Mac/Windows/Linux. It is an interpreted language, so you simply need to have the Python interpreter installed on the system of your choice (it is available for all three platforms).
As for a GUI library that works cross platform, Python's Tk/Tcl widget library works very well, and I believe is sufficiently cross platform.
Tkinter is the python interface to Tk/Tcl
From the python project webpage:
Tkinter is not the only GuiProgramming toolkit for Python. It is however the most commonly used one, and almost the only one that is portable between Unix, Mac and Windows
Upvotes: 1