微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Tkinter / matplotlib osx上的多个活动窗口

我有一个如下的脚本,在我的Windows机器上执行

import matplotlib.pyplot as plt import numpy as np import tkinter class main(tkinter.Frame): #main window def __init__(self,root): # initialise tkinter.Frame.__init__(self) self.root = root tkinter.Button(self,text='New spots',command=self.newSpots).grid() def newSpots(self): x = np.random.rand(10) y = np.random.rand(10) plt.scatter(x,y) plt.show() if __name__=='__main__': root = tkinter.Tk() app = main(root).grid() root.mainloop()

当在窗口上运行时,它会用一个简单的button打开一个窗口,点击这个button打开一个matplotlib查看器,并在随机位置绘制10个点。 随后每按一下button又增加10个点。

在mac上执行此代码生成相同的初始窗口,并且首次按下该button会生成图并按预期打开查看器。 但是,直到观看者窗口closures,才能与原始窗口(只有观看者的控件工作)交互。 我如何使Windows机器上的mac镜像上的行为?

绘制和写入没有窗口的图像文件

在Ubuntu上导入matplotlib

MatplotlibanimationMovieWriters在Ubuntu 12.04上失败

安装matplotlib-venn

RuntimeError:无效的disPLAYvariables

ImportError:没有安装matplotlib的matplotlib模块

在Linux中保存一个matplotlibanimation

Python使用PyCharm在远程服务器上绘图

简单的应用程序使用wxPython和matplotlib冻结

在Python 2.6中导入Pylab的问题

我发现这个问题的解决方案 – 似乎matplotlib认为Windows上的TkAgg后端(我不确定这是一个普通的Windows的东西,或特定于任何特定的安装在计算机上)。

将以下行添加到脚本的顶部会强制TkAgg后端,并在两台机器上导致相同的行为。

import matplotlib matplotlib.use("TkAgg")

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐