我有三個Python(3.4.3)腳本。其中之一是控制由PyQt5生成的.ui文件。當我運行GUI程序時,它接受所有數據和所有內容,並且當我按下InputDialog上的OK按鈕時,窗口關閉並顯示控制檯。python:使用PyCharm和PyQt5完成退出代碼1的過程
Process finished with exit code 1
當我運行的Python IDLE相同的代碼,它顯示:
<<<<<<RESTART>>>>>>
,當我用這個相同的Python(3.4.3或2.7)上的標識碼這絕不happenned工作室。可能是什麼原因?
這裏是控制.ui文件的python文件的代碼。
import sys
from PyQt5 import QtCore, QtGui, uic, QtWidgets
from Email import encrypt_email
from Email import decrypt_email
from Email import newuser
qtCreatorFile = "rsegui.ui" # Enter file here.
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)
class MyApp(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
user, ok = QtWidgets.QInputDialog.getText(self, 'New User',
'Are you a new user?')
user=str(user)
if user in "YESYesyesYy":
email, ok = QtWidgets.QInputDialog.getText(self, 'New User',
'Enter Your Email ID:')
email1=str(email)
self.sender.setText(email)
newuser(email1)
self.encrypt_and_send.clicked.connect(self.EncryptEmail)
self.decrypt.clicked.connect(self.DecryptEmail)
self.clear.clicked.connect(self.ClearEncrypt)
self.clear_2.clicked.connect(self.ClearDecrypt)
self.sender.setPlaceholderText("Your Email ID")
self.receiver.setPlaceholderText("Receivers, Separate them by ';'")
self.subject.setPlaceholderText("Enter Subject")
self.message.setPlaceholderText("Enter Message")
self.sender_2.setPlaceholderText("Your Email ID")
self.message_2.setPlaceholderText("Encrypted Text")
def EncryptEmail(self):
sender = str(self.sender.text())
receiver = str(self.receiver.text())
receivers = receiver.split(';')
subject = str(self.subject.text())
message = str(self.message.text())
password, ok = QtWidgets.QInputDialog.getText(self, 'Password',
'Enter your password:',QtWidgets.QLineEdit.Password)
encrypt_email(sender,receivers,subject,message,password)
def DecryptEmail(self):
email = str(self.sender_2.text())
message = str(self.message_2.text())
self.decrypted.setText(decrypt_email(email,message))
def ClearDecrypt(self):
self.sender_2.clear()
self.message_2.clear()
def ClearEncrypt(self):
self.sender.clear()
self.message.clear()
self.receiver.clear()
self.subject.clear()
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
window = MyApp()
window.show()
sys.exit(app.exec_())
非常好的問題。既然它涉及代碼,我認爲它可能是一個好主意,提供一些,你不覺得嗎?此外,追溯也將非常有用! –
我用代碼更新了問題。沒有追蹤被打印到控制檯。 – daipayan
@ N.Wouda任何想法爲什麼會發生這種情況? – daipayan