from PyQt5.Qt import *
import sys
class Window(QWidget):
def mousePressEvent(self, QMouseEvent):
if self.isMaximized():
self.showNormal()
else:
self.showMaximized()
app=QApplication(sys.argv)
win=Window()
win.resize(500,500)
win.show()
sys.exit(app.exec_())