1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
import sys from PyQt4.QtCore import * from PyQt4.QtGui import *
class window(QWidget): def __init__(self, parent=None): super(window, self).__init__(parent) self.init()
def init(self): layout = QFormLayout() self.btn = QPushButton("Choose from list") self.btn.clicked.connect(self.getItem)
self.le = QLineEdit() layout.addRow(self.btn, self.le) self.btn1 = QPushButton("get name") self.btn1.clicked.connect(self.gettext)
self.le1 = QLineEdit() layout.addRow(self.btn1, self.le1) self.btn2 = QPushButton("Enter an integer") self.btn2.clicked.connect(self.getint)
self.le2 = QLineEdit() layout.addRow(self.btn2, self.le2) self.setLayout(layout) self.setWindowTitle("Input Dialog demo")
def getItem(self): items = ("C", "C++", "Java", "Python")
item, ok = QInputDialog.getItem(self, "select input dialog", "list of languages", items, 0, False)
if ok and item: self.le.setText(item)
def gettext(self): text, ok = QInputDialog.getText(self, 'Text Input Dialog', 'Enter your name:')
if ok: self.le1.setText(str(text))
def getint(self): num, ok = QInputDialog.getInt(self, "integer input dualog", "enter a number")
if ok: self.le2.setText(str(num)) def main(): app = QApplication(sys.argv) ex = window() ex.show() sys.exit(app.exec_())
if __name__ == '__main__': main()
|