创建输入框
# -*- coding: utf-8 -*- import sys from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * class DialogDemo(QMainWindow): def __init__(self, parent=None): super(DialogDemo, self).__init__(parent) self.setWindowTitle("Dialog 例子") self.resize(350, 300) self.btn = QPushButton(self) self.btn.setText("弹出对话框") self.btn.move(50, 50) self.btn.clicked.connect(self.showdialog) def showdialog(self): dialog = QInputDialog() dialog.setInputMode(0) # 0:文本;1:整数;2:浮点数 dialog.setWindowTitle("温馨提示") dialog.setLabelText("设置期号将删除之前所有数据") # 0:文本;1:整数;2:浮点数 dialog.setOkButtonText("确定") dialog.setCancelButtonText("取消") if dialog.exec_() != 0: # 确认 print("enter") if dialog.inputMode() == 0: print(dialog.textValue(), 0) elif dialog.inputMode() == 1: print(dialog.textValue(), 1) elif dialog.inputMode() == 2: print(dialog.doubleValue(), 2) else: # 取消 # print("取消",dialog.intValue()) pass # dialog = QDialog() # btn = QPushButton("确定", dialog) # btn2 = QPushButton("取消", dialog) # Edit = QLineEdit(dialog) # btn.move(20, 50) # btn2.move(110, 50) # Edit.move(40, 20) # dialog.setWindowTitle("Dialog") # dialog.setWindowModality(Qt.ApplicationModal) # dialog.exec_() if __name__ == '__main__': app = QApplication(sys.argv) demo = DialogDemo() demo.show() sys.exit(app.exec_())