# coding: utf-8
import sys
from PyQt4 import QtGui, QtCore
class MyWindow(QtGui.QWidget):
def __init__(self, parent = None): # constructor
QtGui.QWidget.__init__(self, parent) # init parent
self.label = QtGui.QLabel("Привет, мир!") # label
self.label.setAlignment(QtCore.Qt.AlignCenter) # alignment on center
self.btnQuit = QtGui.QPushButton("&Закрыть окно") # button
self.vbox = QtGui.QVBoxLayout() # vertical sizer
self.vbox.addWidget(self.label) # label
self.vbox.addWidget(self.btnQuit) # add button to layout
self.setLayout(self.vbox) # set layout
self.connect(self.btnQuit, QtCore.SIGNAL('clicked()'), QtGui.qApp.quit) # connect button to slot 'quit'
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv) # create object of application
window = MyWindow() # create object of class
window.setWindowTitle("ООП-стиль создания окна") # set title
window.resize(300, 70) # set size
window.show() # show
sys.exit(app.exec_()) # execute application