Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel, QLineEdit, QPushButton
- class MainWindow(QMainWindow):
- def __init__(self):
- super().__init__()
- self.setWindowTitle("Zoo Ali")
- self.setGeometry(100, 100, 600, 600)
- # Tworzenie etykiet i pól tekstowych
- self.label_cats = QLabel("Koty:", self)
- self.label_cats.move(50, 50)
- self.edit_cats = QLineEdit(self)
- self.edit_cats.move(200, 50)
- self.label_canaries = QLabel("Kanarki:", self)
- self.label_canaries.move(50, 100)
- self.edit_canaries = QLineEdit(self)
- self.edit_canaries.move(200, 100)
- self.label_fishes = QLabel("Rybki:", self)
- self.label_fishes.move(50, 150)
- self.edit_fishes = QLineEdit(self)
- self.edit_fishes.move(200, 150)
- self.label_legs = QLabel("Ilość nóg:", self)
- self.label_legs.move(50, 250)
- self.label_legs_result = QLabel("", self)
- self.label_legs_result.move(200, 250)
- self.label_tails = QLabel("Ilość ogonów:", self)
- self.label_tails.move(50, 300)
- self.label_tails_result = QLabel("", self)
- self.label_tails_result.move(200, 300)
- # Tworzenie przycisku
- self.button = QPushButton("Oblicz", self)
- self.button.move(200, 200)
- self.button.clicked.connect(self.calculate)
- def calculate(self):
- # Odczytanie wartości z pól tekstowych
- cats = int(self.edit_cats.text()) if self.edit_cats.text() else 0
- canaries = int(self.edit_canaries.text()) if self.edit_canaries.text() else 0
- fishes = int(self.edit_fishes.text()) if self.edit_fishes.text() else 0
- # Obliczenie sumarycznej ilości nóg i ogonów
- legs = cats * 4 + canaries * 2 + fishes * 0
- tails = cats * 1 + canaries * 1 + fishes * 1
- # Wyświetlenie wyników
- self.label_legs_result.setText(str(legs))
- self.label_tails_result.setText(str(tails))
- if __name__ == "__main__":
- app = QApplication(sys.argv)
- window = MainWindow()
- window.show()
- sys.exit(app.exec())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement