Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from PyQt5 import QtGui
- from PyQt5.QtGui import QPixmap
- from PyQt5.QtWidgets import *
- from PyQt5.uic import loadUi
- class Main(QDialog):
- def __init__(self):
- super(Main, self).__init__()
- loadUi('uis/main.ui', self)
- self.setWindowTitle('Создание простейшей визуальной программы на Python')
- self.setWindowIcon(QtGui.QIcon('images/logo.png'))
- self.label_img.setPixmap(QPixmap('images/main.png'))
- self.label_img.setScaledContents(True)
- self.btn_solve.clicked.connect(self.solve)
- self.btn_clear.clicked.connect(self.clear)
- self.btn_exit.clicked.connect(self.exit)
- def solve(self):
- a = self.lineEdit_a.text()
- b = self.lineEdit_b.text()
- x = self.lineEdit_x.text()
- passed = validation_of_data(a, b, x)
- if passed is True:
- a = float(a)
- b = float(b)
- x = float(x)
- answer = 0.0
- if x > 6:
- answer = a / x + b / x ** 2
- else:
- answer = a ** 2 * (x + b)
- self.label_answer.setText('Ответ: ' + str(answer))
- else:
- self.label_answer.setText('Проверьте правильность введенных данных!')
- def clear(self):
- self.lineEdit_a.setText('')
- self.lineEdit_b.setText('')
- self.lineEdit_x.setText('')
- self.label_answer.setText("Ответ: ")
- def exit(self):
- self.close()
- def validation_of_data(a, b, x):
- try:
- float(a)
- float(b)
- float(x)
- return True
- except Exception:
- return False
- def main():
- app = QApplication(sys.argv)
- window = Main()
- window.show()
- sys.exit(app.exec_())
- if __name__ == '__main__':
- main()
- Python-2:
- ---->images
- ---------->logo.png
- ---------->main.png
- ---->uis
- ---------->main.ui
- ---->Main.py
Add Comment
Please, Sign In to add comment