Want to improve this question? Update the question so it focuses on one problem only by editing this post.
开发者_JAVA百科Closed 8 years ago.
Improve this questionI 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?
Is it, in general, a good idea to write a GUI application in Python?
What is the standard (easiest and most stable) way to create a GUI applications in Python?
Does anybody can give me a link to a simple Hello World GUI application written in Python?
- Depends on what application you are writing. I would use Python for a simple GUI, yes.
- Use a proper toolkit (such as PyQt - Python bindings for the popular Qt)
- 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()
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.
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.
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.
python is ok for gui better than perl and ruby heres some tk
from tkinter import *
from tkinter import ttk
root = Tk()
ttk.Button(root, text="Hello World").grid()
root.mainloop()
If you want to learn some GUI programming in Python using Tkinter, you can see a step-by-step process of building a simple MineSweep clone in twelve progressions here: MineSweep for Python 3.x
精彩评论