This repository has been archived on 2024-08-23. You can view files and clone it, but cannot push or open issues or pull requests.
Files
lessons/Python/pyqt6_4/snippets/9.py

71 lines
1.7 KiB
Python
Executable File

import sys
from enum import StrEnum
from PyQt6.QtGui import QFont
from PyQt6.QtWidgets import (
QApplication,
QComboBox,
QHBoxLayout,
QLabel,
QVBoxLayout,
QWidget,
)
class CatType(StrEnum):
ORANGE = "one orange brain cell"
VOID = "void"
DUST = "dust kitty"
class Window(QWidget):
def __init__(self) -> None:
super().__init__()
self.setGeometry(*(500,) * 4)
self.setWindowTitle("Окно")
self.current_type = CatType.ORANGE
self.create_combo()
def create_combo(self) -> None:
hbox = QHBoxLayout()
label = QLabel("Select cat type:")
label.setFont(QFont("Times", 15))
self.combo = QComboBox(self)
for cat_type in CatType:
self.combo.addItem(cat_type.capitalize())
self.combo.currentTextChanged.connect(self.combo_changed)
hbox.addWidget(label)
hbox.addWidget(self.combo)
vbox = QVBoxLayout()
self.label_result = QLabel(
f"Current cat: {self.current_type.capitalize()}",
)
self.label_result.setFont(QFont("Times", 15))
vbox = QVBoxLayout()
vbox.addWidget(self.label_result)
vbox.addLayout(hbox)
self.setLayout(vbox)
def combo_changed(self) -> None:
self.current_type = CatType(self.combo.currentText().lower())
self.label_result.setText(
f"Current cat: {self.current_type.capitalize()}",
)
def main() -> None:
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec())
if __name__ == "__main__":
main()