from __future__ import division
import sys
from math import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class Form(QDialog):
    def __init__(self,parent=None):
        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.browser.append('%s = <b>%s</b>' % (text,eval(text)))
        except:
            self.browser.append('<font color=red>%s is invalid!</font>' % text)

app=QApplication(sys.argv)
form=Form()
form.show()
app.exec_()

 

相关文章:

  • 2022-02-20
  • 2022-12-23
  • 2022-12-23
  • 2021-07-19
  • 2021-06-26
  • 2022-01-18
  • 2021-11-09
猜你喜欢
  • 2022-01-21
  • 2021-09-11
  • 2021-12-25
  • 2022-12-23
相关资源
相似解决方案