首页 > 编程 > Python > 正文

pyqt4教程之widget使用示例分享

2020-02-23 05:14:43
字体:
来源:转载
供稿:网友


代码如下:
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtCore, QtGui
class MyWindow(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self,parent )
        self.setWindowTitle("weather")
        self.resize(1000, 200)
        girdLayout = QtGui.QGridLayout()
        #标签
        str ="weather"
        label1 = QtGui.QLabel(str)
        girdLayout.addWidget( label1, 0, 0)
        #按钮
        button1 = QtGui.QPushButton('button1')
        girdLayout.addWidget ( button1 , 0, 1)
        #文本条
        textFile = QtGui.QLineEdit()
        girdLayout.addWidget( textFile, 0, 2 )
        #密码条
        passwordFile = QtGui.QLineEdit()
        passwordFile.setEchoMode( QtGui.QLineEdit.Password )
        girdLayout.addWidget( passwordFile, 1, 2)
        #编辑框
        textArea = QtGui.QTextEdit()
        girdLayout.addWidget(textArea , 2, 2 )
        #单选框&复选框
        self.radio1 = QtGui.QRadioButton('radio1')
        self.radio2 = QtGui.QRadioButton('radio2')
        self.radio3 = QtGui.QRadioButton('radio3')
        girdLayout.addWidget( self.radio1 , 3 ,0)
        girdLayout.addWidget( self.radio2 , 3 ,1)
        girdLayout.addWidget( self.radio3 , 3 ,2)
        checkbox1 = QtGui.QCheckBox('checkbox1')
        checkbox2 = QtGui.QCheckBox('checkbox2')
        checkbox3 = QtGui.QCheckBox('checkbox2')
        girdLayout.addWidget( checkbox1 , 4, 0)
        girdLayout.addWidget( checkbox2 , 4, 1)
        girdLayout.addWidget( checkbox3 , 4, 2)

        self.button = QtGui.QPushButton('ok')
        girdLayout.addWidget( self.button, 5 , 0)

        self.connect(self.button ,QtCore.SIGNAL('clicked()'),self.OnButton )

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表