AttributeError : 'FigureManagerBase' object has no attribut 'window'
AttributeError : 'FigureManagerBase' object has no attribut 'window'
下面的python代码我已经很好地使用了,但是当我重新安装Anaconda python 2.7 ver.时,该代码有错误。为什么会这样?
plt.subplots_adjust(top=0.9, bottom=0.05, left=0.05, right=0.95, wspace=0.55, hspace=0.2)
plt.figtext(0.5, 0.95, str(os.path.basename(self.filepath)),ha='center', color='black', weight='bold', size='small')
mngr = plt.get_current_fig_manager()
mngr.window.setGeometry(810, 30, 800, 800)
show()
Traceback (most recent call last):
File "C:\Users\hyeyoung\Desktop200211MHyeyoung.py", line 4482, in onOpenImageFile
self.ShowAFewFrames()
File "C:\Users\hyeyoung\Desktop200211MHyeyoung.py", line 4509, in ShowAFewFrames
mngr.window.setGeometry(810,30,800, 800)
AttributeError: 'FigureManagerBase' object has no attribute 'window'
--------------------------------------------------------------------------
Anaconda python ver. : 2.7
matplotlib ver. :2.2.2
please give me an answer. thx
您假设 plt.get_current_fig_manager()
returns 一个具有 window
属性的对象。只有在使用 Qt4Agg
或 Qt5Agg
(或 Qt4Cairo
/ Qt5Cairo
)后端时才会出现这种情况,因为在那种情况下,图形管理器是 FigureManagerQT
,它是 QtWidgets.QWidget
的子类,Qt 小部件具有 window
属性。
因此,如果您想使用该属性,请确保使用相应的后端,例如
matplotlib.use("Qt5Agg")
下面的python代码我已经很好地使用了,但是当我重新安装Anaconda python 2.7 ver.时,该代码有错误。为什么会这样?
plt.subplots_adjust(top=0.9, bottom=0.05, left=0.05, right=0.95, wspace=0.55, hspace=0.2)
plt.figtext(0.5, 0.95, str(os.path.basename(self.filepath)),ha='center', color='black', weight='bold', size='small')
mngr = plt.get_current_fig_manager()
mngr.window.setGeometry(810, 30, 800, 800)
show()
Traceback (most recent call last):
File "C:\Users\hyeyoung\Desktop200211MHyeyoung.py", line 4482, in onOpenImageFile
self.ShowAFewFrames()
File "C:\Users\hyeyoung\Desktop200211MHyeyoung.py", line 4509, in ShowAFewFrames
mngr.window.setGeometry(810,30,800, 800)
AttributeError: 'FigureManagerBase' object has no attribute 'window'
--------------------------------------------------------------------------
Anaconda python ver. : 2.7
matplotlib ver. :2.2.2
please give me an answer. thx
您假设 plt.get_current_fig_manager()
returns 一个具有 window
属性的对象。只有在使用 Qt4Agg
或 Qt5Agg
(或 Qt4Cairo
/ Qt5Cairo
)后端时才会出现这种情况,因为在那种情况下,图形管理器是 FigureManagerQT
,它是 QtWidgets.QWidget
的子类,Qt 小部件具有 window
属性。
因此,如果您想使用该属性,请确保使用相应的后端,例如
matplotlib.use("Qt5Agg")