[英]Icons missing from PyQt5 app after compiling to .exe using pyinstaller
[英]Fail to run pyqt5 app after compiling the code using cython
這是一個簡單的 PyQt5 應用程序。 其中有一個QCheckBox
,我將其clicked
信號連接到foo()
function。通過單擊此復選框,我將兩個參數傳遞給foo()
function 並將這些參數打印到控制台。 它工作正常但是在我通過單擊此復選框使用 cython 編譯器編譯此代碼后我得到一個TypeError
。
主要文件:
from PyQt5.QtWidgets import QMainWindow, QApplication, QCheckBox
from functools import partial
import sys
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.chb = QCheckBox(self)
self.chb.setText('My CheckBox')
self.chb.move(10, 10)
self.chb.clicked.connect(
partial(self.foo, 'para1', 'para2')
)
def foo(self, p1, p2):
print(p1, p2)
def main():
app = QApplication(sys.argv)
win = MainWindow()
win.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
錯誤:
Traceback (most recent call last):
File "main.pyx", line 15, in main.MainWindow.foo
def foo(self, p1, p2):
TypeError: foo() takes exactly 3 positional arguments (4 given)
安裝程序.py:
from setuptools import setup
from Cython.Build import cythonize
setup(ext_modules = cythonize("main.pyx"))
我在 windows 10 機器上使用 python 3.7。
Cython==0.29.24 和 PyQt5==5.15.4
似乎當 cythonized 發送默認參數時,一個可能的解決方案是將該參數傳遞給它:
def foo(self, p1, p2, checked):
print(p1, p2)
另一種選擇是不使用 functools.partial 而是使用嵌套函數:
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.chb = QCheckBox(self)
self.chb.setText("My CheckBox")
self.chb.move(10, 10)
self.chb.clicked.connect(self.foo('para1', 'para2'))
def foo(self, p1, p2):
def wrapper():
print(p1, p2)
return wrapper
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.