Page List

Sunday, January 22, 2012

Qt Tutorial #1-2 Calling it Quits

This is from Qt Tutorial #1 Calling it quits



#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'''
    PyQt4 conversion of Qt Tutorial 2 
    
last modified: 2012-01-19 jg
ref: http://doc.trolltech.com/3.3/tutorial1-02.html
'''

import sys
from PyQt4.QtGui import (QApplication, QPushButton, QFont)

def main():
    app = QApplication(sys.argv)    # required

    quitBtn = QPushButton('Quit')
    quitBtn.resize(75, 35)
    quitBtn.setFont(QFont("Times", 18, QFont.Bold))

    # Register event handling ('signal/slot' mechanism)
    # when button is clicked, it sends an event message (signal)
    # to a 'method' (slot) for handling
    # in this case, the application 'quit()' method
    quitBtn.clicked.connect(app.quit)  # new style

    quitBtn.show()

    sys.exit(app.exec_())   # start main event loop, exit when app closed

if __name__ == '__main__':
    main()