0
當我調用Error Message One(請參閱代碼中的註釋)時,消息很快出現,然後消失。但是,如果我調用錯誤消息二,它看起來只有當我點擊「確定」按鈕時纔會消失。PyQt5:啓動後QMessageBox消失
我該如何解決它,以便錯誤消息一起工作像錯誤消息二?
try:
connection = pymysql.connect(host = 'localhost',
user = 'root',
db = 'Telephon Register',
cursorclass = pymysql.cursors.DictCursor)
cur = connection.cursor()
if number!= "":
cur.execute("SELECT Number FROM formen WHERE Telephonebook = " + self.number.text())
result = cur.fetchone()
if len(result) == 0:
cur.execute("INSERT INTO formen VALUES(" + self.number.text())
connection.commit()
else:
print("The number " + number+ " already exists.")
else:
print("You have not typed a number!")
msg = QMessageBox() #EXCEPTION MESSAGE ONE
msg.setIcon(2)
msg.setText("Some Text")
msg.setInformativeText("Some informative text")
msg.setWindowTitle("Error")
msg.show()
connection.close()
except:
print("Connection does not work!")
msg = QMessageBox() # EXCEPTION MESSAGE TWO
msg.setIcon(3)
msg.setText("Some Text")
msg.setInformativeText("Some message")
msg.setWindowTitle("Error")
msg.show()
太好了!直到現在我還不知道它。 :) 謝謝! –