我使用matplotlib创建了一个图形窗口,但是我不希望用户手动关闭它。有没有办法禁用右上角的关闭按钮?请参见截图。
我使用matplotlib创建了一个图形窗口,但是我不希望用户手动关闭它。有没有办法禁用右上角的关闭按钮?请参见截图。
import matplotlib
# make sure Qt backend is used
matplotlib.use("Qt4Agg")
from PyQt4 import QtCore
import matplotlib.pyplot as plt
# create a figure and some subplots
fig, ax = plt.subplots(figsize=(4,2))
ax.plot([2,3,5,1])
fig.tight_layout()
win = plt.gcf().canvas.manager.window
win.setWindowFlags(win.windowFlags() | QtCore.Qt.CustomizeWindowHint)
win.setWindowFlags(win.windowFlags() & ~QtCore.Qt.WindowCloseButtonHint)
plt.show()
这将禁用关闭按钮(而不是隐藏它)。
我不确定Tk是否能够控制关闭按钮。但是可以实现绘制一个完全无边框的窗口。
import matplotlib
# make sure Tk backend is used
matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
# create a figure and some subplots
fig, ax = plt.subplots(figsize=(4,2))
ax.plot([2,3,5,1])
fig.tight_layout()
win = plt.gcf().canvas.manager.window
win.overrideredirect(1) # draws a completely frameless window
plt.show()