I am trying to create a simple file selection dialog for one of my scripts and I was trying to use the code examples from this thread: Quick and easy file dialog in Python?
import Tkinter, tkFileDialog
root = Tkinter.Tk()
root.withdraw()
file_path = tkFileDialog.askopenfilename()
I also tried using the easygui module that uses Tkinter to do the same thing. In both cases, the code above hangs the IPython console. I gather that this has something to do with event loops, but I have no real experience with GUIs in Python.
Could someone point me in the right direction on how to get a dialogbox for file selection to work with IPython/Spyder. For the record, I am on Python 2.7.6 and IPython 2.4.1
Before running the code above, you need to set the right event loop (in this case Tk), as you correctly guessed.
To do that you need to run this command:
In [1]: %gui tk
and then run your code.
Note: To access the documentation about the %gui magic in Spyder, you need to place the cursor in front of %gui and press Ctrl+I, like this
In [1]: %gui<Ctrl+I>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With