我试着在confirmPoputWindow上按下enter按钮时运行一个函数inputAttendance(AthleteInfo)。这个函数包含在我导入的另一个文件中,不在任何类中。 我的一个问题是它似乎在运行
self.confirmw.confirmAthlete.connect(inputAttendance(AthleteInfo))
在信号发出之前。一旦inputAttendance()完成,整个窗口将在我收到错误后关闭
argument 1 has unexpected type 'NoneType'
我试着查找它,可能是我没有定义连接类型?在
任何帮助都将不胜感激,因为我已经被困在这个问题上有一段时间了。在
Edit: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_())
你好,先生,这是一个很好的问题,让我们这样总结一下。在
让我们看看这个小例子,它代表了我刚才想总结的内容。
Ps:我做过的一些事情有很多更好的方法,比如变量名、面向对象和组织,但这是你所要求的关键。希望它能更清楚地说明它是如何工作的。:D
相关问题 更多 >
编程相关推荐