Advertisement
programusy

Untitled

Apr 13th, 2023
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 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")
  12. grid = QGridLayout()
  13. self.setLayout(grid)
  14.  
  15. self.label = QLabel("Kalkulator")
  16. self.label.setFont(QFont("Calibri", 21))
  17. grid.addWidget(self.label, 0, 0)
  18.  
  19. self.oblicz_button = QPushButton("Oblicz", self)
  20. self.oblicz_button.clicked.connect(self.oblicz)
  21. grid.addWidget(self.oblicz_button, 3, 1)
  22.  
  23. self.oblicz_button = QPushButton("+", self)
  24. self.oblicz_button.clicked.connect(self.oblicz)
  25. grid.addWidget(self.oblicz_button, 0, 1)
  26.  
  27. self.oblicz_button = QPushButton("-", self)
  28. self.oblicz_button.clicked.connect(self.oblicz)
  29. grid.addWidget(self.oblicz_button, 0, 2)
  30.  
  31. self.oblicz_button = QPushButton("*", self)
  32. self.oblicz_button.clicked.connect(self.oblicz)
  33. grid.addWidget(self.oblicz_button, 0, 3)
  34.  
  35. self.oblicz_button = QPushButton("/", self)
  36. self.oblicz_button.clicked.connect(self.oblicz)
  37. grid.addWidget(self.oblicz_button, 0, 4)
  38.  
  39. self.oblicz_button = QPushButton("%", self)
  40. self.oblicz_button.clicked.connect(self.oblicz)
  41. grid.addWidget(self.oblicz_button, 0, 5)
  42.  
  43. self.textbox1 = QTextEdit('50', self)
  44. grid.addWidget(self.textbox1, 2, 1)
  45. self.textbox2 = QTextEdit('1.6', self)
  46. grid.addWidget(self.textbox2, 2, 2)
  47. self.textbox3 = QTextEdit('0', self)
  48. grid.addWidget(self.textbox3, 2, 3)
  49. #self.textbox4.setGeometry(0,0,0,0)
  50.  
  51. def oblicz(self):
  52. masa = float(self.textbox1.toPlainText())
  53. if self.radiobutton2.isChecked():
  54. masa = masa * 0.4535
  55. print(f"nasa: {masa}")
  56. wzrost = float(self.textbox2.toPlainText())
  57. if self.radiobutton4.isChecked():
  58. wzrost = wzrost * 0.01
  59. print(f"Wzrost: {wzrost}")
  60.  
  61. bmi = masa / (wzrost * wzrost)
  62. print(f"BMI: {bmi}")
  63. self.textbox3.setText(str(bmi))
  64.  
  65. if __name__ == '__main__':
  66. app = QApplication(sys.argv)
  67. MyWindow = MyWindow()
  68. MyWindow.resize(640, 480)
  69. MyWindow.show()
  70. sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement