Advertisement
programusy

Untitled

Apr 5th, 2023
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 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 masę ciała:")
  20. label1.setFont(QFont("Calibri", 16))
  21. grid.addWidget(label1, 1, 0)
  22.  
  23. label2 = QLabel("Podaj wzrost ciała:")
  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('1.6', 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, 0, 1, 2)
  39. #self.textbox4.setGeometry(0,0,0,0)
  40.  
  41. self.radiobutton1 = QRadioButton("kg")
  42. self.radiobutton1.setChecked(True)
  43. self.radiobutton1.toggled.connect(self.oblicz)
  44. grid.addWidget(self.radiobutton1, 1, 2)
  45.  
  46. self.radiobutton2 = QRadioButton("lbs")
  47. self.radiobutton2.setChecked(False)
  48. self.radiobutton2.toggled.connect(self.oblicz)
  49. grid.addWidget(self.radiobutton2, 1, 3)
  50.  
  51. self.masa_radio = QButtonGroup()
  52. self.wzrost_radio = QButtonGroup()
  53.  
  54. self.radiobutton3 = QRadioButton("m")
  55. self.radiobutton3.setChecked(True)
  56. self.radiobutton3.toggled.connect(self.oblicz)
  57. grid.addWidget(self.radiobutton3, 2, 2)
  58.  
  59. self.radiobutton4 = QRadioButton("cm")
  60. self.radiobutton4.setChecked(False)
  61. self.radiobutton4.toggled.connect(self.oblicz)
  62. grid.addWidget(self.radiobutton4, 2, 3)
  63.  
  64. self.masa_radio.addButton(self.radiobutton1)
  65. self.masa_radio.addButton(self.radiobutton2)
  66. self.wzrost_radio.addButton(self.radiobutton3)
  67. self.wzrost_radio.addButton(self.radiobutton4)
  68.  
  69. self.checkbox1 = QCheckBox("Opis")
  70. self.checkbox1.setChecked(False)
  71. self.radiobutton1.toggled.connect(self.oblicz)
  72. grid.addWidget(self.checkbox1, 4, 3)
  73.  
  74. def oblicz(self):
  75. masa = float(self.textbox1.toPlainText())
  76. if self.radiobutton2.isChecked():
  77. masa = masa * 0.4535
  78. print(f"nasa: {masa}")
  79. wzrost = float(self.textbox2.toPlainText())
  80. if self.radiobutton4.isChecked():
  81. wzrost = wzrost * 0.01
  82. print(f"Wzrost: {wzrost}")
  83.  
  84. bmi = masa / (wzrost * wzrost)
  85. print(f"BMI: {bmi}")
  86. self.textbox3.setText(str(bmi))
  87.  
  88. if self.checkbox1.isChecked():
  89. if bmi < 16:
  90. self.textbox4.setText("Wygłodzenie")
  91. elif bmi < 17:
  92. self.textbox4.setText("Wychudzenie")
  93. elif bmi < 18.5:
  94. self.textbox4.setText("Niedowaga")
  95. elif bmi < 25:
  96. self.textbox4.setText("Waga Prawidłowa")
  97. elif bmi < 30:
  98. self.textbox4.setText("Nadwaga")
  99. elif bmi < 35:
  100. self.textbox4.setText("Otylosc 1 stopnia")
  101. elif bmi < 40:
  102. self.textbox4.setText("Otylosc 2 stopnia")
  103. else:
  104. self.textbox4.setText("Otylosc 3 stopnia")
  105. if __name__ == '__main__':
  106. app = QApplication(sys.argv)
  107. MyWindow = MyWindow()
  108. MyWindow.resize(640, 480)
  109. MyWindow.show()
  110. sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement