PyQt5--InputDiaglog
Posted sashuangyibing
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PyQt5--InputDiaglog相关的知识,希望对你有一定的参考价值。
1 # -*- coding:utf-8 -*- 2 ‘‘‘ 3 Created on Sep 14, 2018 4 5 @author: SaShuangYiBing 6 7 Comment: 8 ‘‘‘ 9 import sys 10 from PyQt5.QtWidgets import QApplication,QInputDialog,QLineEdit,QPushButton,QWidget 11 12 class New_test(QWidget): 13 def __init__(self): 14 super().__init__() 15 self.initUI() 16 17 def initUI(self): 18 self.btn = QPushButton(‘Diaglog‘,self) 19 self.btn.move(20,20) 20 self.btn.clicked.connect(self.showDiaglog) 21 22 self.le = QLineEdit() 23 self.le.move(130,22) 24 25 self.setGeometry(300,300,290,150) 26 self.setWindowTitle(‘Input Diaglog‘) 27 self.show() 28 29 def showDiaglog(self): 30 try: 31 text,ok = QInputDialog.getText(self,‘Input Diaglog‘,‘Enter your name‘) 32 if ok: 33 self.le.setText(str(text)) 34 except Exception as e: 35 print (e) 36 37 if __name__ == ‘__main__‘: 38 app = QApplication(sys.argv) 39 ex = New_test() 40 sys.exit(app.exec_())
以上是关于PyQt5--InputDiaglog的主要内容,如果未能解决你的问题,请参考以下文章