import sys from PyQt4.QtGui import QApplication, QWidget, QDesktopWidget app = QApplication(sys.argv) widget = QWidget() widget.resize(250, 150) widget.setWindowTitle('Centered Window') desktop = QDesktopWidget().screenGeometry() x = (desktop.width() - widget.width()) / 2 y = (desktop.height() - widget.height()) / 2 widget.move(x, y) widget.show() sys.exit(app.exec_())
from PyQt4.QtGui import QDesktopWidget desktop = QDesktopWidget() primary_screen = desktop.screenGeometry() print(primary_screen.x(), primary_screen.y(), primary_screen.width(), primary_screen.height())
from PyQt4.QtGui import QDesktopWidget, QApplication import sys app = QApplication(sys.argv) desktop = QDesktopWidget() num_screens = desktop.screenCount() print(num_screens) sys.exit(app.exec_())This code creates a QDesktopWidget object and retrieves the number of screens connected to the system. In summary, the PyQt4 QtGui and QDesktopWidget classes are part of the PyQt4 library, which is used for creating GUI applications in Python. These classes provide functionality for working with graphical components and accessing information about the desktop and screens.