Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from PyQt5.QtGui import *
- from PyQt5.QtCore import *
- from PyQt5.QtGui import *
- from PyQt5.QtWidgets import *
- class MyWindow(QWidget):
- def __init__(self):
- super().__init__()
- self.setWindowTitle("Kalkulator BMI")
- grid = QGridLayout()
- self.setLayout(grid)
- self.label = QLabel("Kalkulator BMI")
- self.label.setFont(QFont("Calibri", 21))
- grid.addWidget(self.label, 0, 0)
- label1 = QLabel("Podaj mase")
- label1.setFont(QFont("Calibri", 16))
- grid.addWidget(label1, 1, 0)
- label2 = QLabel("Podaj wzrost")
- label2.setFont(QFont("Calibri", 16))
- grid.addWidget(label2, 2, 0)
- self.oblicz_button = QPushButton("Oblicz BMI", self)
- self.oblicz_button.clicked.connect(self.oblicz)
- grid.addWidget(self.oblicz_button, 3, 0)
- self.textbox1 = QTextEdit('50', self)
- grid.addWidget(self.textbox1, 1, 1)
- self.textbox2 = QTextEdit('150', self)
- grid.addWidget(self.textbox2, 2, 1)
- self.textbox3 = QTextEdit('0', self)
- grid.addWidget(self.textbox3, 3, 1)
- self.textbox4 = QTextEdit('Opis', self)
- grid.addWidget(self.textbox4, 4, 1)
- self.radiobutton1 = QRadioButton("kg")
- self.radiobutton1.setChecked(True)
- self.radiobutton1.toggled.connect(self.oblicz)
- grid.addWidget(self.radiobutton1, 1, 2)
- self.radiobutton2 = QRadioButton("lbs")
- self.radiobutton2.setChecked(False)
- self.radiobutton2.toggled.connect(self.oblicz)
- grid.addWidget(self.radiobutton2, 1, 3)
- self.radiobutton3 = QRadioButton("m")
- self.radiobutton3.setChecked(True)
- self.radiobutton3.toggled.connect(self.oblicz)
- grid.addWidget(self.radiobutton3, 2, 2)
- self.radiobutton4 = QRadioButton("cm")
- self.radiobutton4.setChecked(False)
- self.radiobutton4.toggled.connect(self.oblicz)
- grid.addWidget(self.radiobutton4, 2, 3)
- def oblicz(self):
- masa = float(self.textbox1.toPlainText())
- if self.radiobutton2.isChecked():
- masa = masa * 0.4535
- print(f"masa: {masa}")
- wzrost = float(self.textbox2.toPlainText())
- if self.radiobutton4.isChecked():
- wzrost = wzrost * 0.01
- print(f"Wzrost: {wzrost}")
- bmi = masa / (wzrost * wzrost)
- print(f"BMI: {bmi}")
- self.textbox3.setText(str(bmi))
- if self.checkbox1.isChecked():
- if bmi <16:
- self.textbox4.setText("Wyglodzenie")
- if bmi <17:
- self.textbox4.setText("Wychudzenie")
- if bmi <16:
- self.textbox4.setText("Wyglodzenie")
- if __name__ == '__main__':
- app = QApplication(sys.argv)
- MyWindow = MyWindow()
- MyWindow.resize(640, 480)
- MyWindow.show()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement