【发布时间】:2017-01-24 01:17:45
【问题描述】:
每当在确认弹出窗口上按下回车按钮时,我都会尝试运行函数 inputAttendance(AthleteInfo)。此函数包含在我导入的另一个文件中,并且不在任何类中。 我遇到的一个问题是它似乎在运行
self.confirmw.confirmAthlete.connect(inputAttendance(AthleteInfo))
在信号发出之前。一旦 inputAttendance() 完成,整个窗口在我收到错误后关闭
参数 1 具有意外类型“NoneType”
我尝试查找它,可能是我没有定义连接类型?
任何帮助将不胜感激,因为我已经坚持了很长一段时间。
编辑:InputAttendance() 是一个函数,用于更新我导入的另一个文件中的电子表格,但由于它与我的问题无关,因此未包含在帖子中。我已经测试了这个函数并且它工作得很好,所以我确定它不会导致程序崩溃,而是它是如何被调用的。很抱歉造成混乱!
from PyQt5.QtWidgets import (QWidget, QPushButton, QLineEdit,
QInputDialog, QApplication, QLabel)
from PyQt5.QtCore import *
class Ex(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.le = QLineEdit(self)
self.le.move(500, 500)
self.le.returnPressed.connect(self.pushEnter)
self.setGeometry(1000, 1000, 1000, 1000)
self.setWindowTitle('Input dialog')
self.show()
def pushEnter(self):
text = self.le.text()
AthleteInfo = getID(text)
if (AthleteInfo == -1):
print ("Could nto find that ID")
else:
try:
self.confirmw =confirmPopup("Confirm Window")
except Exception in e:
print(e)
time.sleep(10)
self.confirmw.setGeometry(1000, 1000, 1000, 1000)
self.confirmw.show()
try:
self.confirmw.setWindowModality(Qt.ApplicationModal)
except Exception as e:
print(e)
time.sleep(5)
try: self.confirmw.confirmAthlete.connect(inputAttendance(AthleteInfo))
except Exception as e:
print(e)
time.sleep(5)
class confirmPopup(QWidget):
confirmAthlete = pyqtSignal(str)
def __init__(self, name):
super().__init__()
self.name = name
self.initUI()
def initUI(self):
lblName = QLabel(self.name, self, text = "Press enter to confirm")
def keyPressEvent(self, event):
keyPress = event.text()
if event.key() == Qt.Key_Enter or event.key() == Qt.Key_Return:
try:
#print("Emitting Signal")
self.confirmAthlete.emit("Yes")
except Exception as e:
print(e)
time.sleep(5)
if event.key() == Qt.Key_Backspace:
print("Backspace was pressed")
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Ex()
sys.exit(app.exec_())
【问题讨论】:
-
什么是 inputAttendance?
-
下面的答案没有用吗?它应该可以完美运行。
-
@Y.Melo 感谢您的回复!我现在正忙着工作/要回学校,所以我明天晚上看看你的回复。