PyQt hello world

#! /usr/bin/env python

import sys

from PyQt4.QtCore import *
from PyQt4.QtGui import *

class HelloButton(QPushButton):
    def __init__(self, *args):
        QPushButton.__init__(self, *args)
        self.setText("Hello World")


class HelloWindow(QMainWindow):
    def __init__(self, *args):
        QMainWindow.__init__(self, *args)
        
        self.button = HelloButton(self)
        QObject.connect(self.button, SIGNAL("clicked()"), self, SLOT("showMessage()"))
        self.setCentralWidget(self.button)
        self.setWindowTitle("hello world")
        
    @pyqtSignature("")
    def showMessage(self):
        QMessageBox.aboutQt(self)


def main(args):
    app = QApplication(args)
    win = HelloWindow()
    win.show()
    app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()"))
    app.exec_()


if __name__ == "__main__":
    main(sys.argv)


你可能感兴趣的:(PyQt hello world)