Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- ###############################################################################
- # calculate project #
- #author: josh #
- ###############################################################################
- from __future__ import division
- import sys
- from math import *
- from PyQt4.QtCore import *
- from PyQt4.QtGui import *
- class Form(QDialog):
- super(Form, self).__init__(parent)
- self.browser = QTextBrowser()
- self.lineedit = QLineEdit("Type an expression and press Enter")
- self.lineedit = selectAll()
- layout = QVBoxLayout()
- layout.addWidget(self.browser)
- layout.addWidget(self.lineedit)
- self.setLayout(layout)
- self.lineedit.setFocus()
- self.connect(self.lineedit, SIGNAL("returnPressed()"),
- self.updateUi)
- self.setWindowTitle("Calculate")
- def updateUi(self):
- try:
- text = unicode(self.lineedit.text())
- self.borwser.append("%s = <b>%s</b>" % (text, eval(text)))
- except:
- self.browser.append(
- "<font color=red>%s is invalid!</font>" % text)
- app = QAppliction(sys.argv)
- form = Form()
- form.show()
- app.exec_()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement