Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. #
  2. ###############################################################################
  3. # calculate project                                                           #
  4. #author: josh                                                                 #
  5. ###############################################################################
  6.  
  7. from __future__ import division
  8. import sys
  9. from math import *
  10. from PyQt4.QtCore import *
  11. from PyQt4.QtGui import *
  12.  
  13. class Form(QDialog):
  14.     super(Form, self).__init__(parent)
  15.     self.browser = QTextBrowser()
  16.     self.lineedit =  QLineEdit("Type an expression and press Enter")
  17.     self.lineedit = selectAll()
  18.     layout = QVBoxLayout()
  19.     layout.addWidget(self.browser)
  20.     layout.addWidget(self.lineedit)
  21.     self.setLayout(layout)
  22.     self.lineedit.setFocus()
  23.     self.connect(self.lineedit, SIGNAL("returnPressed()"),
  24.         self.updateUi)
  25.     self.setWindowTitle("Calculate")
  26. def updateUi(self):
  27.     try:
  28.         text = unicode(self.lineedit.text())
  29.         self.borwser.append("%s = <b>%s</b>" % (text, eval(text)))
  30.     except:
  31.         self.browser.append(
  32.             "<font color=red>%s is invalid!</font>" % text)
  33. app = QAppliction(sys.argv)
  34. form = Form()
  35. form.show()
  36. app.exec_()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement