Advertisement
programusy

Untitled

Mar 8th, 2023
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. import sys
  2. from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton, QVBoxLayout
  3.  
  4. class Okno(QWidget):
  5. def __init__(self):
  6. super().__init__()
  7.  
  8. self.koty_label = QLabel("Ilość kotów:")
  9. self.koty_entry = QLineEdit()
  10. self.ryby_label = QLabel("Ilość ryb:")
  11. self.ryby_entry = QLineEdit()
  12. self.kanar_label = QLabel("Ilość kanarków:")
  13. self.kanar_entry = QLineEdit()
  14. self.wynik_label = QLabel()
  15.  
  16. self.oblicz_button = QPushButton("Oblicz")
  17. self.oblicz_button.clicked.connect(self.oblicz_nogi)
  18.  
  19. vbox = QVBoxLayout()
  20. vbox.addWidget(self.koty_label)
  21. vbox.addWidget(self.koty_entry)
  22. vbox.addWidget(self.ryby_label)
  23. vbox.addWidget(self.ryby_entry)
  24. vbox.addWidget(self.kanar_label)
  25. vbox.addWidget(self.kanar_entry)
  26. vbox.addWidget(self.oblicz_button)
  27. vbox.addWidget(self.wynik_label)
  28. self.setLayout(vbox)
  29.  
  30. def oblicz_nogi(self):
  31. ilosc_kotow = int(self.koty_entry.text())
  32. ilosc_ryb = int(self.ryby_entry.text())
  33. ilosc_kanar = int(self.kanar_entry.text())
  34. suma_nog = 4 * ilosc_kotow + 0 * ilosc_ryb + 2 * ilosc_kanar
  35. self.wynik_label.setText("Ilość nóg: " + str(suma_nog))
  36.  
  37. if __name__ == '__main__':
  38. app = QApplication(sys.argv)
  39. okno = Okno()
  40. okno.show()
  41. sys.exit(app.exec_())
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement