Advertisement
programusy

Untitled

Mar 8th, 2023
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. import sys
  2. from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel, QLineEdit, QPushButton
  3.  
  4. class MainWindow(QMainWindow):
  5. def __init__(self):
  6. super().__init__()
  7. self.setWindowTitle("Zoo Ali")
  8. self.setGeometry(100, 100, 600, 600)
  9.  
  10. # Tworzenie etykiet i pól tekstowych
  11. self.label_cats = QLabel("Koty:", self)
  12. self.label_cats.move(50, 50)
  13. self.edit_cats = QLineEdit(self)
  14. self.edit_cats.move(200, 50)
  15.  
  16. self.label_canaries = QLabel("Kanarki:", self)
  17. self.label_canaries.move(50, 100)
  18. self.edit_canaries = QLineEdit(self)
  19. self.edit_canaries.move(200, 100)
  20.  
  21. self.label_fishes = QLabel("Rybki:", self)
  22. self.label_fishes.move(50, 150)
  23. self.edit_fishes = QLineEdit(self)
  24. self.edit_fishes.move(200, 150)
  25.  
  26. self.label_legs = QLabel("Ilość nóg:", self)
  27. self.label_legs.move(50, 250)
  28. self.label_legs_result = QLabel("", self)
  29. self.label_legs_result.move(200, 250)
  30.  
  31. self.label_tails = QLabel("Ilość ogonów:", self)
  32. self.label_tails.move(50, 300)
  33. self.label_tails_result = QLabel("", self)
  34. self.label_tails_result.move(200, 300)
  35.  
  36. # Tworzenie przycisku
  37. self.button = QPushButton("Oblicz", self)
  38. self.button.move(200, 200)
  39. self.button.clicked.connect(self.calculate)
  40.  
  41. def calculate(self):
  42. # Odczytanie wartości z pól tekstowych
  43. cats = int(self.edit_cats.text()) if self.edit_cats.text() else 0
  44. canaries = int(self.edit_canaries.text()) if self.edit_canaries.text() else 0
  45. fishes = int(self.edit_fishes.text()) if self.edit_fishes.text() else 0
  46.  
  47. # Obliczenie sumarycznej ilości nóg i ogonów
  48. legs = cats * 4 + canaries * 2 + fishes * 0
  49. tails = cats * 1 + canaries * 1 + fishes * 1
  50.  
  51. # Wyświetlenie wyników
  52. self.label_legs_result.setText(str(legs))
  53. self.label_tails_result.setText(str(tails))
  54.  
  55. if __name__ == "__main__":
  56. app = QApplication(sys.argv)
  57. window = MainWindow()
  58. window.show()
  59. sys.exit(app.exec())
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement