pyqt4教程之widget使用示例分享

时间:2021-05-23


复制代码 代码如下:
# -*- 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_()

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章