我写了一个程序,基本上是按不同的按钮绘制不同的数据。该程序在Windows下正常工作,但当我试图将其移植到Linux(redhatv6)时,我遇到了一个奇怪的问题:我要绘制的窗口直到关闭主程序后才会出现。不管我要绘制的是哪个图形(图1、2等),还是要输入,都会发生这种情况表演()等
我写的程序差不多有1000行代码,但是我创建了一个有相同问题的简短程序。它在Windows下工作,但是在Linux下,我必须关闭根窗口才能显示matplotlib窗口。在
工作代码:
import matplotlib.pyplot as plt
from tkinter import *
def click():
x=['0','1','2']
plt.plot(x,x)
plotGUI=Tk()
butt1=Button(plotGUI,text="Test", command=click).grid()
plotGUI.mainloop()
我只需简单地加上:
这使得程序可以像在Windows中一样工作,无需任何其他必要的修改。不过,我真的需要学习user3666197发布的概念,以便将来的项目使用。在
如果简化代码仍然没有显示Tk顶层窗口,则添加一行:
如果简化代码在
matplotlib
-包装器方面有问题,那么有必要更具体地说明您使用什么包装方法将matplitlib
-输出放入Tkinter画布等。在如果代码试图依赖默认的
matplotlib
工具plt.show()
,那么代码将遭受两个相邻的.mainloop()
-s第一个是Tk()
的第二个默认隐藏在matplotlib
-s.show()
中,因此您的代码很难控制两个相邻的UI-s协同集成UI
为了拥有非相邻的UI控制器和更多的协同集成UI的好处, 尝试重用后端工厂,直接在
^{pr2}$Tkinter.Canvas
和您选择和控制的其他合理的小部件上绘图。在并继续在代码和matplotlib模型状态/输入控制器/视觉输出上实现完全集成的GUI-MVC层。在
关于协同集成UI示例的更多代码:
[Halldinz0r]按原样复制/粘贴重新测试的完整代码:
相关问题 更多 >
编程相关推荐