from PySide2 import QtWidgets def center_window(w): qr = w.frameGeometry() cp = QtWidgets.QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) w.move(qr.topLeft())