0
我有一個使用PyQt創建的GUI。在GUI中,它們是一個按鈕,當按下時發送一些數據給客戶端。以下是我的代碼以乾淨的方式停止執行代碼python
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()
目前,如果用戶點擊「OK」在QMessageBox提示程序將繼續的情況下,代碼執行的是插座例外。因此,我的問題是,如何以乾淨的方式停止「except」之後的代碼執行,以便我的UI不會崩潰並且用戶可以繼續使用它?
我可以寫簡單的空回報'return'而不是'pass' – prattom