from PySide6.QtCore import QSize from PySide6.QtWidgets import QApplication, QLabel, QPushButton, QMainWindow, QWidget, QBoxLayout from PySide6.QtGui import QPixmap from typing import final import sys app = QApplication(sys.argv) @final class Movie: def __init__(self, name: str, price: float, image: QWidget): self.name = name self.price = price self.image = image def createImage(filename: str) -> QWidget: label = QLabel() pixmap = QPixmap(filename) label.setPixmap(pixmap.scaled(300, 300)) return label movies = { "spiderman": Movie("Spider-Man: Very far from home", 39.95, createImage("resources/spiderman.png")), "cars2": Movie("Cars 2", 79.95, createImage("resources/cars2.png")), "leo": Movie("The Nerd Movie", -189.95, createImage("resources/leo.png")) } class MovieView(QWidget): def __init__(self, movie: Movie): super().__init__() layout = QBoxLayout(QBoxLayout.Direction.TopToBottom) self.setWindowTitle("Movie viewer") label1 = QLabel(f"Buying a ticket for {movie.name}") label2 = QLabel(f"For cost ${movie.price}") label3 = movie.image layout.addWidget(label1) layout.addWidget(label2) layout.addWidget(label3) self.setLayout(layout) # Main Window class MainWindow(QMainWindow): def __init__(self): super().__init__() self.takers: list[MovieView] = [] self.setWindowTitle("Cinema Tickets"); layout = QBoxLayout(QBoxLayout.Direction.LeftToRight) self.spiderman: QPushButton = QPushButton("Buy tickets for spider man"); self.spiderman.setCheckable(True) _ = self.spiderman.clicked.connect(self.buySpiderman) layout.addWidget(self.spiderman) self.cars: QPushButton = QPushButton("Buy tickets for cars 2"); self.cars.setCheckable(True) _ = self.cars.clicked.connect(self.buyCars) layout.addWidget(self.cars) self.leo: QPushButton = QPushButton("Buy tickets for the nerd movie"); self.leo.setCheckable(True) _ = self.leo.clicked.connect(self.buyLeo) layout.addWidget(self.leo) centralWidget = QWidget() centralWidget.setLayout(layout) self.setCentralWidget(centralWidget) def buySpiderman(self): self.setCentralWidget(MovieView(movies["spiderman"])) def buyLeo(self): self.setCentralWidget(MovieView(movies["leo"])) def buyCars(self): self.setCentralWidget(MovieView(movies["cars2"])) window = MainWindow() window.show() exit(app.exec())