(PyQt和PySide)QFileDialog.getExistingDirectory在Windows上不起作用

时间:2021-12-01 23:44:23

This code works perfectly fine on mac, after clicking on the button, the dir dialog show up. On Windows, it freezes after the button clicks (refer to the picture).

这段代码在mac上完美运行,点击按钮后,dir对话框显示出来。在Windows上,按钮点击后会冻结(参见图片)。

Here is my code:

这是我的代码:

import os 
import sys
from Pyside import QtGui

class OpenDir(QtGui.QWidget):
   def __init__(self):
      super(OpenDir, self).__init__()
      self.initUI()

   def initUI(self):
      self.openDir = QtGui.QPushButton('Dialog', self)
      self.openDir.move(20, 20);
      self.openDir.clicked.connect(self.open_dir)
      self.show()

   def open_dir(self):
      self.filename = QtGui.QFileDialog.getExistingDirectory(self, 
                                             "open dir", os.getcwd())

def main():
   app = QtGui.QApplication(sys.argv)
   ui = OpenDir()
   sys.exit(app.exec_())

if __name__ == '__main__':
   main()

Updated:

Error after clicking on dialog button.

单击对话框按钮后出错。

1 个解决方案

#1


I fixed my problem by installing Python 3.4.3. So I assume this must be compatibility between PyQt/PySide and Python distributions (Anaconda).

我通过安装Python 3.4.3解决了我的问题。所以我认为这必须是PyQt / PySide和Python发行版(Anaconda)之间的兼容性。

#1


I fixed my problem by installing Python 3.4.3. So I assume this must be compatibility between PyQt/PySide and Python distributions (Anaconda).

我通过安装Python 3.4.3解决了我的问题。所以我认为这必须是PyQt / PySide和Python发行版(Anaconda)之间的兼容性。