[英]PyQT5 QFileDialog issues with Pyinstaller
我在 Arch Linux 上使用 PyQt5 和 Pycharm 和 Python 3.7(也尝试过 3.8)。 当我从 PyCharm 或直接从命令行运行我的代码时,文件对话框打开正常。 但是,当我使用Pyinstaller构建时,在使用它们时会出现一致的错误。 代码:
def choose_log_location(self):
self.log_location = QFileDialog.getExistingDirectory(
self,
"Choose Log Files Directory",
"/home",
options=QFileDialog.ShowDirsOnly)
if self.log_location != "":
self.Log_Location.setText(self.log_location)
使用 Pyinstaller 构建后,运行构建的应用程序并单击触发此方法的按钮,我会弹出 3 个错误对话框:
然后,一旦真正弹出文件对话框,主要区域是空白的。
我还在控制台中收到以下错误:
kf5.kio.core: "" qt.qpa.xcb: QXcbConnection: XCB 错误: 3 (BadWindow), 序列: 7952, 资源 id: 36398251, 主要代码: 40 (TranslateCoords), 次要代码: 0
我也使用 QFileDialog.getOpenFileName() 遇到了一些类似的问题(文件应该是空白区域 - 注意没有过滤器测试,结果相同)但控制台中出现不同的错误:
kf5.kservice.services: KServiceTypeTrader: serviceType "ThumbCreator" not found
我有同样的问题。 pyinstaller 似乎会在本机对话框中产生此错误。 所以我的解决方案是使用DontUseNativeDialog
选项。
例如
self.log_location = QFileDialog.getExistingDirectory(
self,
"Choose Log Files Directory",
"/home",
QFileDialog.DontUseNativeDialog)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.