Python 2.7 如何在python中关闭QMessageBox及其父对话框
按下Python 2.7 如何在python中关闭QMessageBox及其父对话框,python-2.7,pyqt,qdialog,Python 2.7,Pyqt,Qdialog,按下ok按钮时,如何关闭弹出对话框及其QMessageBox.information 我从你那里得到这个密码 我将它用作模块中的弹出对话框。该对话框将打开另一个QMessageBox。信息及其标准ok按钮 我想在按下ok按钮时同时关闭窗口3和窗口2,因为它在QMessageBox.information(self,'Success',Opened%s successfully'%cur\u item.text()),您只需说self.accept()。这将关闭2个和3个窗口。太棒了……终于解
ok
按钮时,如何关闭弹出对话框及其QMessageBox.information
我从你那里得到这个密码
我将它用作模块中的弹出对话框。该对话框将打开另一个QMessageBox。信息
及其标准ok
按钮
我想在按下ok按钮时同时关闭窗口3和窗口2,因为它在
QMessageBox.information(self,'Success',Opened%s successfully'%cur\u item.text())
,您只需说self.accept()
。这将关闭2个和3个窗口。太棒了……终于解决了!!你能解释一下它是如何工作的吗……我是python的新手,让事情理解@Achayan和:)
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import serial
from serial.serialutil import SerialException
from serialutils import full_port_name, enumerate_serial_ports
class ListPortsDialog(QDialog):
def __init__(self, parent=None):
super(ListPortsDialog, self).__init__(parent)
self.setWindowTitle('List of serial ports')
self.ports_list = QListWidget()
self.tryopen_button = QPushButton('Try to open')
self.connect(self.tryopen_button, SIGNAL('clicked()'),
self.on_tryopen)
layout = QVBoxLayout()
layout.addWidget(self.ports_list)
layout.addWidget(self.tryopen_button)
self.setLayout(layout)
self.fill_ports_list()
def on_tryopen(self):
cur_item = self.ports_list.currentItem()
if cur_item is not None:
fullname = full_port_name(str(cur_item.text()))
try:
ser = serial.Serial(fullname, 38400)
ser.close()
QMessageBox.information(self, 'Success',
'Opened %s successfully' % cur_item.text())
except SerialException, e:
QMessageBox.critical(self, 'Failure',
'Failed to open %s:\n%s' % (
cur_item.text(), e))
def fill_ports_list(self):
for portname in enumerate_serial_ports():
self.ports_list.addItem(portname)
if __name__ == "__main__":
app = QApplication(sys.argv)
form = ListPortsDialog()
form.show()
app.exec_()