#-*-Coding:utf-8-*-
From Pyqt4.qtcore Import *
From Pyqt4.qtgui Import *
Import Sys
QTEXTCODEC.SETCODECFORTR (Qtextcodec.codecforname ("UTF8"))
Class InputDlg (Qdialog):
def __init__ (Self,parent=none):
Super (Inputdlg,self). __init__ (parent)
Label1=qlabel (self.tr (" name "))
Label2=qlabel (self.tr (" gender "))
Label3=qlabel (self.tr (" Age "))
Label4=qlabel (self.tr (" height "))
Self.namelabel=qlabel ("Tengwei")
Self.nameLabel.setFrameStyle (qframe.panel| Qframe.sunken)
Self.sexlabel=qlabel (self.tr (" male "))
Self.sexLabel.setFrameStyle (qframe.panel| Qframe.sunken)
Self.agelabel=qlabel ("25")
Self.ageLabel.setFrameStyle (qframe.panel| Qframe.sunken)
Self.staturelabel=qlabel ("168")
Self.statureLabel.setFrameStyle (qframe.panel| Qframe.sunken)
Namebutton=qpushbutton ("...")
Sexbutton=qpushbutton ("...")
Agebutton=qpushbutton ("...")
Staturebutton=qpushbutton ("...")
Self.connect (Namebutton,signal ("clicked ()"), Self.slotname)
Self.connect (Sexbutton,signal ("clicked ()"), Self.slotsex)
Self.connect (Agebutton,signal ("clicked ()"), Self.slotage)
Self.connect (Staturebutton,signal ("clicked ()"), Self.slotstature)
Layout=qgridlayout ()
Layout.addwidget (label1,0,0)
Layout.addwidget (self.namelabel,0,1)
Layout.addwidget (namebutton,0,2)
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.setwindowtitle (self.tr (" data collection "))
def slotname (self):
Name,ok=qinputdialog.gettext (self,self.tr (" username "), self.tr (" Please enter a new name :"), Qlineedit.normal,self.namelabel.text ())
If OK:
Self.nameLabel.setText (name)
def slotsex (self):
List=qstringlist ()
List.append (U ' m ')
List.append (U ' female ')
Sex,ok=qinputdialog.getitem (self,self.tr (" gender "), self.tr ( " Please select Gender "), list)
If OK:
Self.sexLabel.setText (Sex)
def slotage (self):
Age,ok=qinputdialog.getinteger (self,self.tr (" Age "),
self.tr (" Please 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 (" Please enter your height :"),
Float (Self.statureLabel.text ()), 0,2300.00)
If OK:
Self.statureLabel.setText (str (stature))
App=qapplication (SYS.ARGV)
Form=inputdlg ()
Form.show ()
APP.EXEC_ ()
A wonderful example of PYQT practice x3