gpt4 book ai didi

python Qt4 如何绑定(bind)按钮单击操作

转载 作者:行者123 更新时间:2023-11-28 21:30:18 26 4
gpt4 key购买 nike

我正在尝试制作我的第一个Python应用程序。我想制作简单的电子邮件发件人表格。在qt设计器中创建一个dialog.ui,然后从dialog.ui生成dialog.py并在那里编写函数

def SendEmail(self,efrom,eto,esubj,ebody):
msg = MIMEText( ebody.encode('UTF-8'),'html', 'UTF-8')
msg['Subject'] = esubj
msg['From'] = efrom
msg['To'] = eto
s = smtplib.SMTP()
s.connect("mail.driversoft.net", 25)
s.login("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="345d5a525b74594d475d40511a5a5140" rel="noreferrer noopener nofollow">[email protected]</a>", "1234567")
s.sendmail(efrom, [eto], msg.as_string())
s.quit()

并尝试连接到插槽

QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), self.SendEmail("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d0b9beb6bf90bda9a3b9a4b5febeb5a4" rel="noreferrer noopener nofollow">[email protected]</a>", "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f581908681b5988c869c8190db9b9081" rel="noreferrer noopener nofollow">[email protected]</a>", "subject", "bodytext"))

当我尝试启动此应用程序时,我在电子邮件恢复消息和控制台中看不到表单

Traceback (most recent call last):
File "C:\Documents and Settings\a.ivanov\My Documents\Aptana Studio Workspace\test1\src\wxtest.py", line 61, in <module>
ui.setupUi(Dialog)
File "C:\Documents and Settings\a.ivanov\My Documents\Aptana Studio Workspace\test1\src\wxtest.py", line 33, in setupUi
QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), self.SendEmail("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ec85828a83ac81959f9d859889c2828998" rel="noreferrer noopener nofollow">[email protected]</a>", "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="047061777044697d776d70612a6a6170" rel="noreferrer noopener nofollow">[email protected]</a>", "subject", "bodytext"))
TypeError: arguments did not match any overloaded call:
QObject.connect(QObject, SIGNAL(), QObject, SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type 'NoneType'
QObject.connect(QObject, SIGNAL(), callable, Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type 'NoneType'
QObject.connect(QObject, SIGNAL(), SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 2 has unexpected type 'bytes'

如何制作一个表格,我写了主题和文本,然后按“发送”按钮并通过电子邮件接收消息?谢谢!

完整代码

from PyQt4 import QtCore, QtGui
import smtplib
from email.mime.text import MIMEText

class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(400, 330)
self.textEdit = QtGui.QTextEdit(Dialog)
self.textEdit.setGeometry(QtCore.QRect(10, 70, 381, 221))
self.textEdit.setObjectName("textEdit")
self.subjEdit = QtGui.QLineEdit(Dialog)
self.subjEdit.setGeometry(QtCore.QRect(10, 30, 371, 20))
self.subjEdit.setObjectName("subjEdit")
self.pushButton = QtGui.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(100, 300, 75, 23))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtGui.QPushButton(Dialog)
self.pushButton_2.setGeometry(QtCore.QRect(210, 300, 75, 23))
self.pushButton_2.setObjectName("pushButton_2")
self.label = QtGui.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(10, 10, 46, 13))
self.label.setObjectName("label")
self.label_2 = QtGui.QLabel(Dialog)
self.label_2.setGeometry(QtCore.QRect(11, 53, 46, 13))
self.label_2.setObjectName("label_2")

self.retranslateUi(Dialog)
QtCore.QObject.connect(self.pushButton_2, QtCore.SIGNAL("clicked()"), Dialog.close)
QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), self.SendEmail("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6e070008012e03171d071a0b40000b1a" rel="noreferrer noopener nofollow">[email protected]</a>", "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4034253334002d39332934256e2e2534" rel="noreferrer noopener nofollow">[email protected]</a>", "subject", "bodytext"))
QtCore.QMetaObject.connectSlotsByName(Dialog)

#this is my function
def SendEmail(self,efrom,eto,esubj,ebody):
msg = MIMEText( ebody.encode('UTF-8'),'html', 'UTF-8')
msg['Subject'] = esubj
msg['From'] = efrom
msg['To'] = eto
s = smtplib.SMTP()
s.connect("mail.driversoft.net", 25)
s.login("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b7ded9d1d8f7dacec4dec3d299d9d2c3" rel="noreferrer noopener nofollow">[email protected]</a>", "1234567")
s.sendmail(efrom, [eto], msg.as_string())
s.quit()
#print("done")

def retranslateUi(self, Dialog):
Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate("Dialog", "Send", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_2.setText(QtGui.QApplication.translate("Dialog", "Close", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("Dialog", "Subject", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("Dialog", "Email text", None, QtGui.QApplication.UnicodeUTF8))


if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Dialog = QtGui.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())

最佳答案

QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), self.SendEmail("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3a53545c557a574349534e5f14545f4e" rel="noreferrer noopener nofollow">[email protected]</a>", "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0773627473476a7e746e736229696273" rel="noreferrer noopener nofollow">[email protected]</a>", "subject", "bodytext"))

信号槽系统不是这样工作的。您的信号“clicked()”没有参数 - 所以您的插槽也必须没有参数。并且您必须传递对回调的引用,而不是在连接中调用该函数。

QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), self.pushButtonClicked)

def pushButtonClicked(self):
self.SendEmail("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="51383f373e113c28223825347f3f3425" rel="noreferrer noopener nofollow">[email protected]</a>", "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aedacbdddaeec3d7ddc7dacb80c0cbda" rel="noreferrer noopener nofollow">[email protected]</a>", "subject", "bodytext")

关于python Qt4 如何绑定(bind)按钮单击操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3245202/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com