0

The common regular python file dialog from Tk crashes under Enthought Canopy.

What is the recommended way to get a file dialog for Canopy users?

The code below works fine for regular python:

import Tkinter, tkFileDialog

root = Tkinter.Tk()
root.withdraw()

file_path = tkFileDialog.askopenfilename()

Error msg when run under Canopy is:

2014-12-30 11:22:52.809 Python[51980:d0f] -[QNSApplication _setup:]: unrecognized selector sent to instance 0x108657b70
2
  • 1
    The following might be relevant: support.enthought.com/entries/… Commented Dec 30, 2014 at 20:54
  • That explains why Tk could have problems. Still, there must be an easy way to get a file dialog under Canopy. Commented Dec 30, 2014 at 21:08

2 Answers 2

1

Depends on what GUI backend you are using in your program. If your program also uses TK elsewhere, then follow the instructions in the link that Warren provided. 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). I'm no Qt guru but I think you can simplify Chuck's suggestion to:

from PySide import QtGui
fname, _ = QtGui.QFileDialog.getOpenFileName(None, 'Choose file','.')

See http://srinikom.github.io/pyside-docs/PySide/QtGui/QFileDialog.html

Sign up to request clarification or add additional context in comments.

Comments

1

For me, the easy alternative is to use Qt.

fname, _ = QtGui.QFileDialog.getOpenFileName(self.view, 'Open file','.')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.