pyqt5-QInputDialog输入对话框
1、介绍
QInputDialog输入对话框,提供了五种输入模式,进行快捷的输入交互。
- 对话框打开时,无论是否设置parent,都不能操作其它窗口
- 返回tuple类型,索引1为bool类型,为True表示点击Ok按钮关闭对话框,为False则是点击Cancle按钮或窗口右上角关闭按钮
- 调用方法时,必须设置相关的必要参数。但是可以设置包括parent在内的参数为None占位,显示会使用默认值
2、五种输入模式
2.1 整数
getInt(parent: QWidget, title: str, label: str, value: int = 0, min: int = -2147483647, max: int = 2147483647, step: int = 1,
flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags()) -> Tuple[int, bool]
2.2 浮点数
getDouble(parent: QWidget, title: str, label: str, value: float = 0, min: float = -2147483647, max: float = 2147483647,
decimals: int = 1, flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags()) -> Tuple[float, bool]
getDouble(parent: QWidget, title: str, label: str, value: float, minValue: float, maxValue: float, decimals: int,
flags: Union[Qt.WindowFlags, Qt.WindowType], step: float) -> Tuple[float, bool]
2.3 字符串
getText(parent: QWidget, title: str, label: str, echo: QLineEdit.EchoMode = QLineEdit.Normal, text: str = '',
flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags(), inputMethodHints: Union[Qt.InputMethodHints,
Qt.InputMethodHint] = Qt.ImhNone) -> Tuple[str, bool]
2.4 多行文本
getMultiLineText(parent: QWidget, title: str, label: str, text: str = '', flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags(),
inputMethodHints: Union[Qt.InputMethodHints, Qt.InputMethodHint] = Qt.ImhNone) -> Tuple[str, bool]
2.5 下拉列表
getItem(parent: QWidget, title: str, label: str, items: Iterable[str], current: int = 0, editable: bool = True,
flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags(), inputMethodHints: Union[Qt.InputMethodHints,
Qt.InputMethodHint] = Qt.ImhNone) -> Tuple[str, bool]
3、示例
a = QInputDialog.getInt(None, None, None)
print(type(a), a)
b = QInputDialog.getText(self.window, '文本', '输入')
print(type(b), b)
c = QInputDialog.getDouble(self.window, '浮点数', '输入')
print(type(c), c)
d = QInputDialog.getItem(self.window, 'item', '输入', ['a','b','c'])
print(type(d), d)
e = QInputDialog.getMultiLineText(self.window, '多行文本', '输入')
print(type(e), e)