Advertisement
programusy

Untitled

Mar 22nd, 2023
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. import sys
  2. from PyQt5.QtGui import *
  3. from PyQt5.QtCore import *
  4. from PyQt5.QtGui import *
  5. from PyQt5.QtWidgets import *
  6.  
  7.  
  8. class MyWindow(QWidget):
  9. def __init__(self):
  10. super().__init__()
  11. self.setWindowTitle("Kalkulator BMI")
  12. grid = QGridLayout()
  13. self.setLayout(grid)
  14.  
  15. self.label = QLabel("Kalkulator BMI")
  16. self.label.setFont(QFont("Calibri", 21))
  17. grid.addWidget(self.label, 0, 0)
  18.  
  19. label1 = QLabel("Podaj mase")
  20. label1.setFont(QFont("Calibri", 16))
  21. grid.addWidget(label1, 1, 0)
  22.  
  23. label2 = QLabel("Podaj wzrost")
  24. label2.setFont(QFont("Calibri", 16))
  25. grid.addWidget(label2, 2, 0)
  26.  
  27. self.oblicz_button = QPushButton("Oblicz BMI", self)
  28. self.oblicz_button.clicked.connect(self.oblicz)
  29. grid.addWidget(self.oblicz_button, 3, 0)
  30.  
  31. self.textbox1 = QTextEdit('50', self)
  32. grid.addWidget(self.textbox1, 1, 1)
  33. self.textbox2 = QTextEdit('150', self)
  34. grid.addWidget(self.textbox2, 2, 1)
  35. self.textbox3 = QTextEdit('0', self)
  36. grid.addWidget(self.textbox3, 3, 1)
  37. self.textbox4 = QTextEdit('Opis', self)
  38. grid.addWidget(self.textbox4, 4, 1)
  39.  
  40. self.radiobutton1 = QRadioButton("kg")
  41. self.radiobutton1.setChecked(True)
  42. self.radiobutton1.toggled.connect(self.oblicz)
  43. grid.addWidget(self.radiobutton1, 1, 2)
  44.  
  45. self.radiobutton2 = QRadioButton("lbs")
  46. self.radiobutton2.setChecked(False)
  47. self.radiobutton2.toggled.connect(self.oblicz)
  48. grid.addWidget(self.radiobutton2, 1, 3)
  49.  
  50. self.radiobutton3 = QRadioButton("m")
  51. self.radiobutton3.setChecked(True)
  52. self.radiobutton3.toggled.connect(self.oblicz)
  53. grid.addWidget(self.radiobutton3, 2, 2)
  54.  
  55. self.radiobutton4 = QRadioButton("cm")
  56. self.radiobutton4.setChecked(False)
  57. self.radiobutton4.toggled.connect(self.oblicz)
  58. grid.addWidget(self.radiobutton4, 2, 3)
  59.  
  60. def oblicz(self):
  61. masa = float(self.textbox1.toPlainText())
  62. if self.radiobutton2.isChecked():
  63. masa = masa * 0.4535
  64. print(f"masa: {masa}")
  65. wzrost = float(self.textbox2.toPlainText())
  66. if self.radiobutton4.isChecked():
  67. wzrost = wzrost * 0.01
  68. print(f"Wzrost: {wzrost}")
  69.  
  70. bmi = masa / (wzrost * wzrost)
  71. print(f"BMI: {bmi}")
  72. self.textbox3.setText(str(bmi))
  73.  
  74. if self.checkbox1.isChecked():
  75. if bmi <16:
  76. self.textbox4.setText("Wyglodzenie")
  77. if bmi <17:
  78. self.textbox4.setText("Wychudzenie")
  79. if bmi <16:
  80. self.textbox4.setText("Wyglodzenie")
  81.  
  82. if __name__ == '__main__':
  83. app = QApplication(sys.argv)
  84. MyWindow = MyWindow()
  85. MyWindow.resize(640, 480)
  86. MyWindow.show()
  87. sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement