- Modal - Handles all data manipulations
- View - Handles the display
- Controller - Handles the communications between Modal and View
open a terminal and do pip install pyqt6 pip install mutagen
To get a basic window
# Do the imports
import sys
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QGridLayout, QLabel,
QFrame)
from PyQt5.QtCore import Qt
class Modal:
''' Class will handle data manipulations '''
pass
class Window(QMainWindow):
''' Class will handle the display '''
def __init__(self):
QMainWindow.__init__(self)
self.setWindowTitle('My Music Player')
# Sets a fixed size for the window
self.setFixedSize(1280,720)
# Create a main container - will hold all other widgets and layouts
container = QGridLayout()
# Create a header label
header = QLabel('My Music Player')
header.setFrameShape(QFrame.Shape.Box)
header.setFrameShadow(QFrame.Shadow.Raised)
header.setLineWidth(3)
# Just like in css - set color and background color and the like. Is a bit limited.
header.setStyleSheet('font-size: 48px; color: gold; \
font-weight: bold; font-family: comic sans ms; \
background-color: seagreen; padding: 10px;')
# Aligning the text to the center
header.setAlignment(Qt.AlignmentFlag.AlignCenter)
# section for adding widgets to main container
container.addWidget(header, 0, 0, 1, 3, Qt.AlignmentFlag.AlignTop)
# Sets main layout
widget = QWidget()
widget.setLayout(container)
self.setCentralWidget(widget)
class Controller:
def __init__(self, modal, window):
self.modal = modal
self.window = window
if __name__ == '__main__':
app = QApplication([])
controller = Controller(Modal(), Window())
controller.window.show()
sys.exit(app.exec())
The Classes we use from PyQ5 are:
- QApplication
- QMainWindow - subclassed
- QGrid Layout - Like it sounds. Allows us to place our widgets using a grid
- QLabel - Allows to create labels
- Qt - Allows help with aligning text and widgets
- QFrame - put a border around the header label