tags:

views:

264

answers:

4

I would like to try to write a GUI application in Python. I found out that there are a lot of ways to do it (different toolkits). And, in this context, I have several basic (and I think simple) question?

  1. Is it, in general, a good idea to write a GUI application in Python?

  2. What is the standard (easiest and most stable) way to create a GUI applications in Python?

  3. Does anybody can give me a link to a simple Hello World GUI application written in Python?

+4  A: 
  1. Depends on what application you are writing. I would use Python for a simple GUI, yes.
  2. Use a proper toolkit (such as PyQt - Python bindings for the popular Qt)
  3. Sure

Hello world in PyQt:

import qt,sys

a = qt.QApplication(sys.argv)
w = qt.QPushButton("Hello World",None)

a.setMainWidget(w)
w.show()
a.exec_loop()
Yuval A
i think u can speedy develop by use qtdesigner and pyuic to get a looking good ui in python , :)
vernomcrp
A: 

If you're looking to make a fairly simple GUI, then PyGTK is extremely easy to use:

http://www.pygtk.org/

A tutorial (with downloadable sample code) can be found here, and another one on the Wiki.

seanhodges
+1  A: 

Not quite a duplicate, but this SO posting should give you a comparison of some Python GUI toolkits that would answer #3.

As an answer for #1: Yes. It is quite good for this; scripting languages with GUI toolkits are often a good way to put a GUI on an application. They can also be used to wrap applications written in low level languages such as C or C++. Python offers good integration to quite a few toolkits. The posting linked above gives a pretty good cross section of the options with code samples.

For #2: TkInter comes with the standard distribution. It is easy to use but not as sophisticated as (say) QT or WxWidgets.

ConcernedOfTunbridgeWells
I tried the Tkinter and my program writes "ImportError: No module named _tkinter, pleas install the python-tk package".
Roman
@Roman: we need to know which platform you are using. Presumably you are either using Windows and didn't include Tk when installing Python, or you are using Unix/Linux and you need to install a seperate package.
Bastien Léonard
+2  A: 

I am really fond of pygtk and glade. Pygtk is a python binding for gtk, the gui toolkit used in gnome. Glade is a user interface designer which stores a gui as xml, which can be loaded in pygtk.

If you want to see some example code, you can take a look at my project https://launchpad.net/pumped. Just download the source.

rioch