PyQt4簡單小demo

#coding=utf-8

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

class FontPropertiesDlg(QDialog):

    #初始化
    def __init__(self,parent=None):
        #super函數完成對話框的初始化
        super(FontPropertiesDlg,self).__init__(parent)
        FontStyleLabel =QLabel(u'中文字體:')
        FontStyleComboBox=QComboBox()
        FontStyleComboBox.addItems([u'宋體',u'黑體',u'仿宋',u'隸書',u'楷體'])
        FontSizeLabel =QLabel(u'字體大小')
        FontSizeSpinBox=QSpinBox()
        FontSizeSpinBox.setRange(0,90)
        FontEffectCheckBox=QCheckBox(u'使用特效')
        okButton=QPushButton(u'肯定')
        cancelButton=QPushButton(u'取消')
        #確認控件的佈局
        buttonLayout=QHBoxLayout()
        buttonLayout.addStretch()
        buttonLayout.addWidget(okButton)
        buttonLayout.addWidget(cancelButton)
        layout=QGridLayout()
        layout.addWidget(FontStyleLabel,0,0)
        layout.addWidget(FontStyleComboBox,0,1)
        layout.addWidget(FontSizeLabel,1,0)
        layout.addWidget(FontSizeSpinBox,1,1)
        layout.addWidget(FontEffectCheckBox,1,2)
        layout.addLayout(buttonLayout,2,0,1,3)
        self.setLayout(layout)
        #窗口的標題
        self.setWindowTitle(u'字體')

if __name__=='__main__':
    app=QApplication(sys.argv)
    font=FontPropertiesDlg()
    font.show()
    app.exec()
相關文章
相關標籤/搜索