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")
- grid = QGridLayout()
- self.setLayout(grid)
- self.label = QLabel("Kalkulator")
- self.label.setFont(QFont("Calibri", 21))
- grid.addWidget(self.label, 0, 0)
- self.oblicz_button = QPushButton("Oblicz", self)
- self.oblicz_button.clicked.connect(self.oblicz)
- grid.addWidget(self.oblicz_button, 3, 1)
- self.oblicz_button = QPushButton("+", self)
- self.oblicz_button.clicked.connect(self.oblicz)
- grid.addWidget(self.oblicz_button, 0, 1)
- self.oblicz_button = QPushButton("-", self)
- self.oblicz_button.clicked.connect(self.oblicz)
- grid.addWidget(self.oblicz_button, 0, 2)
- self.oblicz_button = QPushButton("*", self)
- self.oblicz_button.clicked.connect(self.oblicz)
- grid.addWidget(self.oblicz_button, 0, 3)
- self.oblicz_button = QPushButton("/", self)
- self.oblicz_button.clicked.connect(self.oblicz)
- grid.addWidget(self.oblicz_button, 0, 4)
- self.oblicz_button = QPushButton("%", self)
- self.oblicz_button.clicked.connect(self.oblicz)
- grid.addWidget(self.oblicz_button, 0, 5)
- self.textbox1 = QTextEdit('50', self)
- grid.addWidget(self.textbox1, 2, 1)
- self.textbox2 = QTextEdit('1.6', self)
- grid.addWidget(self.textbox2, 2, 2)
- self.textbox3 = QTextEdit('0', self)
- grid.addWidget(self.textbox3, 2, 3)
- #self.textbox4.setGeometry(0,0,0,0)
- def oblicz(self):
- masa = float(self.textbox1.toPlainText())
- if self.radiobutton2.isChecked():
- masa = masa * 0.4535
- print(f"nasa: {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 __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