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?

我正在尝试为我的一个脚本创建一个简单的文件选择对话框,我试图使用此线程中的代码示例: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.

我也尝试使用使用Tkinter的easygui模块做同样的事情。在这两种情况下,上面的代码都会挂起IPython控制台。我认为这与事件循环有关,但我对Python中的GUI没有实际经验。

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

有人能指出我如何获得一个文件选择对话框以与IPython / Spyder一起工作的正确方向。为了记录,我使用的是Python 2.7.6和IPython 2.4.1

1 个解决方案

#1


Before running the code above, you need to set the right event loop (in this case Tk), as you correctly guessed.

在运行上面的代码之前,您需要设置正确的事件循环(在本例中为Tk),正如您正确猜到的那样。

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

注意:要访问有关Spyder中%gui magic的文档,您需要将光标放在%gui前面并按Ctrl + I,就像这样

In [1]: %gui<Ctrl+I>

更多相关文章

  1. 在混合的Bash-Python代码片段中,变量的双引号和单引号
  2. 八大经典排序算法基本思想及代码实现(插入排序,希尔排序,选择排序,
  3. 贝叶斯学习 -- matlab、python代码分析(3)
  4. UNIX-LINUX编程实践教程->第八章->实例代码注解->写一个简单的sh
  5. Linux下objdump查看C程序编译后的汇编代码
  6. 软交换FreeSWITCH系统概要和源代码分析预备知识
  7. 如何卸载内核代码中的文件系统
  8. Linux内核源代码情景分析读书笔记(5)-关于fork/clone/vfork
  9. Linux下各类TCP网络服务器的实现源代码

随机推荐

  1. Android USB debugging 功能失效
  2. Android开发7:单元测试
  3. 仿UC底部菜单栏实例源码
  4. 在Android上创建一个PopupWindow
  5. Android Support Package 支撑包
  6. 在sd卡存储文件
  7. Android(安卓)SB的一面,BUG汇总
  8. Android 解决布局问题
  9. Android Studio 自定义Apk的名字
  10. Android获得全局进程信息以及进程使用的