Reputation: 67
I used matplotlib to create a graphics window, but I do not want the user to manually close it. Is there a way to disable the closing button in the upper right corner? See screenshot
Upvotes: 3
Views: 2156
Reputation: 339340
The solution will depend on the backend in use.
For the PyQt backend, you can do the following:
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()
This will disable the close button (not hide it).
I'm not sure if Tk is able to control the close button. But what is possible is to draw a completely frameless window.
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()
Upvotes: 3