pyqt4教程之widget使用示例分享

# -*- 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 )
self.setLayout( girdLayout)

def OnButton(self ):
if self.radio2.isChecked():
self.radio2.setText(‘haha’)

app = QtGui.QApplication( sys.argv )
mywindow = MyWindow()
mywindow.show()
app.exec_()

郑重声明:本网站发布的内容(图片、视频和文字)以及用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服

发表评论

登录后才能评论