Guest User

Untitled

a guest
Jun 13th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. import sys
  2.  
  3. from PyQt5 import QtGui
  4. from PyQt5.QtGui import QPixmap
  5. from PyQt5.QtWidgets import *
  6. from PyQt5.uic import loadUi
  7.  
  8.  
  9. class Main(QDialog):
  10. def __init__(self):
  11. super(Main, self).__init__()
  12. loadUi('uis/main.ui', self)
  13.  
  14. self.setWindowTitle('Создание простейшей визуальной программы на Python')
  15.  
  16. self.setWindowIcon(QtGui.QIcon('images/logo.png'))
  17. self.label_img.setPixmap(QPixmap('images/main.png'))
  18. self.label_img.setScaledContents(True)
  19.  
  20. self.btn_solve.clicked.connect(self.solve)
  21. self.btn_clear.clicked.connect(self.clear)
  22. self.btn_exit.clicked.connect(self.exit)
  23.  
  24. def solve(self):
  25. a = self.lineEdit_a.text()
  26. b = self.lineEdit_b.text()
  27. x = self.lineEdit_x.text()
  28.  
  29. passed = validation_of_data(a, b, x)
  30.  
  31. if passed is True:
  32. a = float(a)
  33. b = float(b)
  34. x = float(x)
  35.  
  36. answer = 0.0
  37.  
  38. if x > 6:
  39. answer = a / x + b / x ** 2
  40. else:
  41. answer = a ** 2 * (x + b)
  42.  
  43. self.label_answer.setText('Ответ: ' + str(answer))
  44. else:
  45. self.label_answer.setText('Проверьте правильность введенных данных!')
  46.  
  47. def clear(self):
  48. self.lineEdit_a.setText('')
  49. self.lineEdit_b.setText('')
  50. self.lineEdit_x.setText('')
  51. self.label_answer.setText("Ответ: ")
  52.  
  53. def exit(self):
  54. self.close()
  55.  
  56.  
  57. def validation_of_data(a, b, x):
  58. try:
  59. float(a)
  60. float(b)
  61. float(x)
  62.  
  63. return True
  64. except Exception:
  65. return False
  66.  
  67.  
  68. def main():
  69. app = QApplication(sys.argv)
  70. window = Main()
  71. window.show()
  72. sys.exit(app.exec_())
  73.  
  74.  
  75. if __name__ == '__main__':
  76. main()
  77.  
  78. Python-2:
  79. ---->images
  80. ---------->logo.png
  81. ---------->main.png
  82. ---->uis
  83. ---------->main.ui
  84. ---->Main.py
Add Comment
Please, Sign In to add comment