Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write GUI in Python? [closed]

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?

like image 710
Roman Avatar asked Feb 22 '10 10:02

Roman


People also ask

Is PySimpleGUI better than Tkinter?

The amount of code required to implement custom GUIs is much shorter using PySimpleGUI than if the same GUI were written directly using Tkinter or Qt. PySimpleGUI code can be “ported” between GUI frameworks by changing import statements.


4 Answers

  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()
like image 83
Yuval Adam Avatar answered Sep 18 '22 14:09

Yuval Adam


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.

  • http://www.gtk.org/
  • http://www.pygtk.org/
  • http://glade.gnome.org/

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

like image 21
Jon Avatar answered Sep 20 '22 14:09

Jon


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.

like image 37
seanhodges Avatar answered Sep 19 '22 14:09

seanhodges


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.

like image 21
ConcernedOfTunbridgeWells Avatar answered Sep 21 '22 14:09

ConcernedOfTunbridgeWells