欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

pyqt4教程之widget使用示例分享

程序员文章站 2023-11-04 22:18:52
复制代码 代码如下:# -*- coding: utf-8 -*-import sysfrom pyqt4 import qtcore, qtguiclass mywind...


复制代码 代码如下:

# -*- 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_()