【问题标题】:Have Pyplot windows appear as topmost window in Windows 7让 Pyplot 窗口显示为 Windows 7 中的最顶层窗口
【发布时间】:2015-06-08 18:03:25
【问题描述】:

我在 Spyder 环境中使用 Anaconda 和 Python 2.7。绘制 pyplot 时,窗口隐藏在我所有其他打开的窗口后面,而不是出现在前面。我怎样才能让人物出现在所有其他打开的窗口前面?

matplotlib 后端是:Qt4Agg

【问题讨论】:

  • 我也很喜欢,但据我所知,这是一个 pyplot 的东西,不能改变太多。但我很乐意以其他方式展示......
  • 这取决于你使用的 pyplot/matplotlib 后端;您可以将其添加到您的问题中吗? (import matplotlib; matplotlib.get_backend() 告诉你哪个。)大多数都有这个功能;但如果一切都失败了,您可以随时使用PyWin32 模块并在绘图窗口上调用SetForegroundWindow
  • 我使用 Qt4Agg 作为后端。

标签: python windows matplotlib anaconda spyder


【解决方案1】:

(Spyder dev here) 唯一具有此功能的后端是TkAgg。 @valentin 在他/她的答案中发布的代码在使用该后端时应该可以工作。

所有其他后端都错过了这种可能性。这一直是 Matplotlib 的一个已知限制,如 Github issue 所示。

【讨论】:

    【解决方案2】:

    你可以试试这样的:

    fig = plt.figure()
    plt.show()
    
    fig.canvas.manager.window.activateWindow()
    fig.canvas.manager.window.raise_()
    

    但所需的行为取决于后端。 在 tkinter 上:

    fm = plt.get_current_fig_manager() 
    #bring to front
    fm.window.attributes('-topmost', 1)
    #allow other windows to cover
    fm.window.attributes('-topmost', 0)
    

    【讨论】:

    • 第一种方法确实适用于我在 Mac OS 上的 Python3.5 和 SpyderPrefs 设置为Qt4Agg。 Spyder 2.3.8、Python 3.5.1 64 位、Qt 4.8.7、Darwin 上的 PyQt4 (API v2) 4.11.4
    猜你喜欢
    • 2011-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-06
    相关资源
    最近更新 更多