def __init__(self, parent_object: QtWidgets.QMainWindow, width: int, height: int, title: str): super().__init__(parent_object) main_window_size = parent_object.geometry() x = main_window_size.x() + (main_window_size.width() - width) // 2 y = main_window_size.y() + (main_window_size.height() - height) // 2 self.setGeometry(x, y, width, height) self.setFixedSize(width, height) self.setWindowIcon(QtGui.QIcon("img/icon.png")) self.setWindowTitle(title) self.main_window = parent_object
combined = QPixmap(Cell.CELL_WIDTH - pading, Cell.CELL_HEIGHT - pading) combined.fill(Qt.transparent) painter = QPainter(combined) for obj in self.objects.values(): painter.drawPixmap(0, 0, obj.pixmap.scaled(Cell.CELL_WIDTH - pading, Cell.CELL_HEIGHT - pading, Qt.KeepAspectRatio)) painter.end() self.setPixmap(combined) self.repaint() if __name__ == '__main__': app = QApplication([]) ventana = QMainWindow() mundo = VirtualWorld(ventana) ventana.setCentralWidget(mundo) ventana.resize(500, 600) ventana.setWindowTitle('Virtual World') ventana.show() screen = QDesktopWidget().screenGeometry() size = ventana.geometry() ventana.move((screen.width()-size.width())/2, (screen.height()-size.height())/2) sys.exit(app.exec_())