相关疑难解决方法(0)

在Mac OS X上使用Tkinter和Matplotlib重复对话窗口

我是Tkinter的新手.我尝试使用下一个代码打开文件tkFileDialog.askopenfilename,然后使用Matplotlib绘制一些内容:

import matplotlib.pyplot as plt
import Tkinter, tkFileDialog

root = Tkinter.Tk()
root.withdraw()
file_path = tkFileDialog.askopenfilename()

x = range(10)
plt.plot(x)
plt.show()
Run Code Online (Sandbox Code Playgroud)

运行上面的脚本后,我得到一个对话窗口来打开我的文件.文件选择后,我会重复对话窗口打开文件,并在屏幕底部打开一个新窗口.我知道问题是因为plt.show().会发生什么以及如何避免重新打开对话框窗口?我应该为我的任务设置Matplotlib后端吗?

我的版本:

Tcl/Tk 8.5.9

Matplotlib 1.3.1

Tkinter $ Revision:81008 $

OS X 10.9.4

我找到了两个相关的stackoverflow问题: pyplot-show-reopens-old-tkinter-dialogmatplotlib-figures-not-working-after-tkinter-file-dialog 但没有答案.这似乎root.destroy()对我不起作用.

python macos tkinter matplotlib python-2.7

3
推荐指数
1
解决办法
2320
查看次数

标签 统计

macos ×1

matplotlib ×1

python ×1

python-2.7 ×1

tkinter ×1