【发布时间】:2014-01-27 15:41:06
【问题描述】:
我有一个使用 PyQt 创建的 GUI。在 GUI 中,它们是一个按钮,按下时会向客户端发送一些数据。以下是我的代码
class Main(QtGui.QTabWidget, Ui_TabWidget):
def __init__(self):
QtGui.QTabWidget.__init__(self)
self.setupUi(self)
self.pushButton_8.clicked.connect(self.updateActual)
def updateActual():
self.label_34.setText(self.comboBox_4.currentText())
HOST = '127.0.0.1' # The remote host
PORT = 8000 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((displayBoard[str(self.comboBox_4.currentText())], PORT))
except socket.error as e:
err1 = str(self.comboBox_4.currentText()) + " is OFF-LINE"
reply2 = QtGui.QMessageBox.critical(self, 'Error', err1, QtGui.QMessageBox.Ok)
if reply2 == QtGui.QMessageBox.Ok:
pass #stop execution at this point
fileName = str(self.comboBox_4.currentText()) + '.txt'
f = open(fileName)
readLines = f.readlines()
line1 = int(readLines[0])
f.close()
目前,如果用户在 QMessageBox 中单击“确定”,程序将继续执行代码,以防出现套接字异常。因此,我的问题是如何以干净的方式停止执行“除外”之后的代码,以使我的 UI 不会崩溃并且用户可以继续使用它?
【问题讨论】:
-
我可以只写空返回'return'而不是'pass'
标签: python-2.7 pyqt