You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
2 years ago
|
from PyQt5.QtWidgets import QDialog, QFormLayout, QLineEdit, QDialogButtonBox, QMessageBox
|
||
|
from PyQt5.QtGui import QIcon
|
||
|
from PyQt5.QtCore import Qt
|
||
|
|
||
|
class DeviceDialog(QDialog):
|
||
|
def __init__(self, parent=None):
|
||
|
super().__init__(parent)
|
||
|
|
||
|
self.initUI()
|
||
|
|
||
|
def initUI(self):
|
||
|
layout = QFormLayout()
|
||
|
|
||
|
deviceName = QLineEdit()
|
||
|
deviceName.setObjectName('deviceName')
|
||
|
|
||
|
layout.addRow("设备名:", deviceName)
|
||
|
|
||
|
button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
|
||
|
ok_button = button_box.button(QDialogButtonBox.Ok)
|
||
|
ok_button.setText("确定") # 设置Ok按钮的文本
|
||
|
|
||
|
cancel_button = button_box.button(QDialogButtonBox.Cancel)
|
||
|
cancel_button.setText("取消") # 设置Cancel按钮的文本
|
||
|
|
||
|
button_box.accepted.connect(self.check_input)
|
||
|
button_box.rejected.connect(self.reject)
|
||
|
|
||
|
layout.addRow(button_box)
|
||
|
|
||
|
self.setWindowIcon(QIcon('Static/zhjt.ico'))
|
||
|
self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # 去掉标题栏的问号
|
||
|
self.setLayout(layout)
|
||
|
self.setWindowTitle("设备信息")
|
||
|
|
||
|
def getParameters(self):
|
||
|
deviceName = self.findChild(QLineEdit, "deviceName").text()
|
||
|
return deviceName
|
||
|
|
||
|
def check_input(self):
|
||
|
deviceName = self.getParameters()
|
||
|
if not deviceName:
|
||
|
QMessageBox.warning(self, '警告', '请输入设备名')
|
||
|
else:
|
||
|
self.accept() # 所有输入都是数字且不为空时接受对话框
|