Ohai! 2011/1/17 Fars- mo <far...@live.com>: > Hugo Parente Lima wrote: >> > [2] http://bugs.openbossa.org/show_bug.cgi?id=607 > > >> It's something that you can use on your projects but not necessarily need to >> be on PySide itself, IMO your attempt to simplify the code failed, not by >> your >> bad, but because the original code is already too simple. > > Wouldn't it be plain beauty to be able to write a one-line hello world? > > with QtGui.QApplication: QtGui.QLabel("Hello world!").show()
The one-liner wouldn't work, because the QLabel will be destroyed after show() was called (because it drops out of context - you have to keep a reference to it for it to stay alive). This can be done with a simple context manager, actually: ============ from contextlib import contextmanager import sys from PySide.QtGui import * @contextmanager def QtApp(): app = QApplication(sys.argv) yield app sys.exit(app.exec_()) ============ Usage: with QtApp(): l = QLabel("Hello world!") l.show() Or also with access to the QApplication object should the need arise: with QtApp() as app: w = QMainWindow() w.setWindowTitle('blubb') pb = QPushButton('heya') pb.clicked.connect(lambda: app.exit(2)) w.setCentralWidget(pb) w.show() Have fun :) Thomas _______________________________________________ PySide mailing list PySide@lists.openbossa.org http://lists.openbossa.org/listinfo/pyside