PyQt4-(6) Tutorial 4



#!/usr/bin/env python
#
 -*- coding:utf-8 -*-
#
 PyQt tutorial 4
#
 Modified by Wubin Qu [quwubin AT gmail.com]
#
 Blog: http://quwubin.cnblogs.com/

# Python 和 Qt都是面向对象的,所以这里用类把tutorial 3
#
 中的例子封装起来


import sys
from PyQt4 import QtCore, QtGui


class MyWidget(QtGui.QWidget):
    
def __init__(self, parent=None):
        QtGui.QWidget.
__init__(self, parent)
          
#首先建立一个类叫做MyWidget,因为他从QtGui.QWidget
          #继承而来。所以必须要两次调用构造方法,一个是MyWidget类的,
          #另一个是父类的。
        self.setFixedSize(200120)
          
# 调整window大小
          
        self.quit 
= QtGui.QPushButton("Quit", self)
        self.quit.setGeometry(
62407530)
        
# setGeometry()在这里做两件事情,一是指定了窗口在屏幕中的位置,
           # 二就是指定了窗口的大小。前面两个参数是x和y坐标,
           # 后面两个是窗口的width和height。
        self.quit.setFont(QtGui.QFont("Times"18, QtGui.QFont.Bold))

        self.connect(self.quit, QtCore.SIGNAL(
"clicked()"),
                     QtGui.qApp, QtCore.SLOT(
"quit()"))



app 
= QtGui.QApplication(sys.argv)
widget 
= MyWidget()
widget.show()
sys.exit(app.exec_())

posted on 2008-06-24 20:42  屈武斌  阅读(651)  评论(0)    收藏  举报

导航