Pyqt uses the example of a standard input box for learning. It is provided by the analysis of pyqt4 wonderful instances.

Source: Internet
Author: User

#-*-Coding: UTF-8 -*-

# Python: 2.x

_ Author _ = 'admin'

 

From pyqt4.qtgui import *

From pyqt4.qt import *

From pyqt4.qtcore import *

Import sys

Qtextcodec. setcodecfortr (qtextcodec. codecforname ("utf8 "))

Class Example (qdialog ):

Def _ init _ (self, parent = none ):

Super (example, self). _ init _ (parent)

Label2 = qlabel (self. tr ("gender "))

Label3 = qlabel (self. tr ("Age "))

Label4 = qlabel (self. tr ("height "))

Self. sexlabel = qlabel (self. tr ("male "))

Sexbutton = qpushbutton ("...")

Agebutton = qpushbutton ("...")

Staturebutton = qpushbutton ("...")

 

Self. sexlabel = qlabel (self. tr ("male "))

Self. sexlabel. setframestyle (qframe. Panel | qframe. Sunken)

# Qframe. panelqframe indicates that the content of a panel is concave or concave.

# Qframe. Sunken frame and content appear sunk; draw a 3 D concave line using the light of the current color and the dark color group

Self. agelabel = qlabel ("25 ")

Self. agelabel. setframestyle (qframe. Panel | qframe. Sunken)

Self. staturelabel = qlabel ("168 ")

Self. staturelabel. setframestyle (qframe. Panel | qframe. Sunken)

Layout = qgridlayout ()

Layout. addwidget (label2, 1, 0)

Layout. addwidget (self. sexlabel, 1, 1)

Layout. addwidget (sexbutton, 1, 2)

Layout. addwidget (label3, 2, 0)

Layout. addwidget (self. agelabel, 2, 1)

Layout. addwidget (agebutton, 2, 2)

Layout. addwidget (label4, 3, 0)

Layout. addwidget (self. staturelabel, 3, 1)

Layout. addwidget (staturebutton, 3, 2)

 

Self. setlayout (layout)

Self. Connect (sexbutton, signal ("clicked ()"), self. slotsex)

Self. Connect (agebutton, signal ("clicked ()"), self. slotage)

Self. Connect (staturebutton, signal ("clicked ()"), self. slotstature)

Def slotsex (Self ):

Listsex = qstringlist ()

Listsex. append (u'male ')

Listsex. append (u'female ')

Sex, OK = qinputdialog. getitem (self, self. tr ('gender'), self. tr ('select gender '),

Listsex)

If OK:

Self. sexlabel. settext (sex)

 

Def slotage (Self ):

Age, OK = qinputdialog. getinteger (self, self. tr ("Age "),

Self. tr ("Enter age :"),

INT (self. agelabel. Text (), 0,150)

If OK:

Self. agelabel. settext (STR (AGE ))

 

Def slotstature (Self ):

Stature, OK = qinputdialog. getdouble (self, self. tr ("height "),

Self. tr ("Enter Height :"),

Float (self. staturelabel. Text (), 0, 2300.00)

If OK:

Self. staturelabel. settext (STR (stature ))

APP = qapplication (SYS. argv)

X = example ()

X. Show ()

Sys.exit(app.exe C _())

:

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.