Initial commit
This commit is contained in:
96
app.py
Normal file
96
app.py
Normal file
@@ -0,0 +1,96 @@
|
||||
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", 0, 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.takers.append(MovieView(movies["spiderman"]))
|
||||
self.takers[-1].show()
|
||||
|
||||
def buyLeo(self):
|
||||
self.takers.append(MovieView(movies["leo"]))
|
||||
self.takers[-1].show()
|
||||
|
||||
def buyCars(self):
|
||||
self.takers.append(MovieView(movies["cars2"]))
|
||||
self.takers[-1].show()
|
||||
|
||||
|
||||
window = MainWindow()
|
||||
window.show()
|
||||
|
||||
exit(app.exec())
|
||||
BIN
resources/cars2.png
Normal file
BIN
resources/cars2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 75 KiB |
BIN
resources/leo.png
Normal file
BIN
resources/leo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.7 MiB |
BIN
resources/spiderman.png
Normal file
BIN
resources/spiderman.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
Reference in New Issue
Block a user