QInputDialog

#!/usr/bin/python import sys from PyQt4 import QtGui from PyQt4 import QtCore class InputDialog(QtGui.QWidget): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.hbox=QtGui.QHBoxLayout(self) self.btn_1=QtGui.QPushButton('Text',self) self.btn_2=QtGui.QPushButton('passwd',self) self.lbl_1=QtGui.QLineEdit() self.hbox.addWidget(self.btn_1) self.hbox.addWidget(self.btn_2) self.hbox.addWidget(self.lbl_1) self.connect(self.btn_1, QtCore.SIGNAL('clicked()'), self.textDialog) self.connect(self.btn_2, QtCore.SIGNAL('clicked()'), self.pswdDialog) def textDialog(self): text, ok = QtGui.QInputDialog.getText(self, / 'Input Dialog', 'Enter your name:') if ok: self.lbl_1.setText(unicode(text)) def pswdDialog(self): pswd, ok = QtGui.QInputDialog.getText(self, / 'Input Dialog', / 'Enter your passwd:', / QtGui.QLineEdit.Password) if ok: self.lbl_1.setText(unicode(pswd)) app = QtGui.QApplication(sys.argv) icon = InputDialog() icon.show() app.exec_()

你可能感兴趣的:(python)