AttributeError:“FigureManagerBase”对象没有属性“window”

2024-09-24 22:29:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经很好地使用了下面的python代码,但是当我重新安装Anaconda python 2.7版本时,该代码有一个错误。为什么会这样

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\Desktop\20200211MHyeyoung.py", line 4482, in onOpenImageFile
    self.ShowAFewFrames()

  File "C:\Users\hyeyoung\Desktop\20200211MHyeyoung.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

Tags: 代码inpyselflinepltanacondawindow
1条回答
网友
1楼 · 发布于 2024-09-24 22:29:48

假设plt.get_current_fig_manager()返回一个具有window属性的对象。只有在使用Qt4AggQt5Agg(或Qt4Cairo/Qt5Cairo)后端时才会出现这种情况,因为在这种情况下,图形管理器是FigureManagerQT,它是QtWidgets.QWidget的子类,而Qt小部件具有window属性

因此,如果要使用该属性,请确保使用相应的后端,例如

matplotlib.use("Qt5Agg")

相关问题 更多 >