[英]Need file dialog for code running in Enthought Canopy
The common regular python file dialog from Tk crashes under Enthought Canopy. 来自Tk的常见常规python文件对话框在理想机盖下崩溃。
What is the recommended way to get a file dialog for Canopy users? 为Canopy用户获取文件对话框的推荐方法是什么?
The code below works fine for regular python: 以下代码适用于常规python:
import Tkinter, tkFileDialog
root = Tkinter.Tk()
root.withdraw()
file_path = tkFileDialog.askopenfilename()
Error msg when run under Canopy is: 在Canopy下运行时,错误消息为:
2014-12-30 11:22:52.809 Python[51980:d0f] -[QNSApplication _setup:]: unrecognized selector sent to instance 0x108657b70
对我来说,简单的选择是使用Qt。
fname, _ = QtGui.QFileDialog.getOpenFileName(self.view, 'Open file','.')
Depends on what GUI backend you are using in your program. 取决于您在程序中使用的GUI后端。 If your program also uses TK elsewhere, then follow the instructions in the link that Warren provided.
如果您的程序还在其他地方使用TK,请按照Warren提供的链接中的说明进行操作。 If all you need is this dialog (and similar), Chuck's suggestion is probably easiest (especially since Qt is the default backend for IPython kernel that Canopy uses).
如果只需要该对话框(或类似对话框),Chuck的建议可能是最简单的(尤其是因为Qt是Canopy使用的IPython内核的默认后端)。 I'm no Qt guru but I think you can simplify Chuck's suggestion to:
我不是Qt专家,但我认为您可以将Chuck的建议简化为:
from PySide import QtGui
fname, _ = QtGui.QFileDialog.getOpenFileName(None, 'Choose file','.')
See http://srinikom.github.io/pyside-docs/PySide/QtGui/QFileDialog.html 参见http://srinikom.github.io/pyside-docs/PySide/QtGui/QFileDialog.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.