gpt4 book ai didi

python - pyqtSlot函数

转载 作者:太空宇宙 更新时间:2023-11-04 08:39:36 27 4
gpt4 key购买 nike

<分区>

我刚从 here 读了一篇关于 pyqt5 按钮的教程.代码如下。有一个关于button.clicked.connect(self.on_click)@pyqtSlot() 的问题。如果我从代码中删除 @pyqtSlot(),它仍然有效。但是,如果我从代码中删除 button.clicked.connect(self.on_click),该按钮将不起作用。那么这段代码中@pyqtSlot()的作用是什么呢?

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot

class App(QWidget):

def __init__(self):
super().__init__()
self.title = 'PyQt5 button - pythonspot.com'
self.left = 10
self.top = 10
self.width = 320
self.height = 200
self.initUI()

def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)

button = QPushButton('PyQt5 button', self)
button.setToolTip('This is an example button')
button.move(100,70)
button.clicked.connect(self.on_click)

self.show()

@pyqtSlot()
def on_click(self):
print('PyQt5 button click')

if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())

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