Pyqt4 Tutorial widget Using sample sharing

Source: Internet
Author: User
The code is as follows:


#-*-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)
#单选框 & check box
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_ ()

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.