如果您不熟悉PyQt4,可以在PyQt Wiki上找到一些有用的教程来入门。
但是与此同时,这是您的“ Hello World”示例:
from PyQt4 import QtGui, QtCoreclass Window(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) self.button = QtGui.QPushButton('Test', self) self.button.clicked.connect(self.handleButton) layout = QtGui.QVBoxLayout(self) layout.addWidget(self.button) def handleButton(self): print ('Hello World')if __name__ == '__main__': import sys app = QtGui.QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec_())


