1. Environment Construction Link: http://www.jianshu.com/p/094928ac0b73
2. qt Create Canvas
Now you need to complete the adder, two numbers A and B are added, and the numbers A and B are entered by digital. Drag the element to complete the interface, such as. On the left there is a simple addition input and output display box, click on the calculation button below to start the calculation, to the right there is an output historical calculation of the page. You can see the name of each dragged element and the corresponding class at the element list, all of which are on MainWindow and Centralwidget
Remember that the names of the elements we set are: digital inputs are textEdit, textedit_2, digital output is textedit_3,textedit_4, calculation process Textedit_5,textedit_ 6 The calculated record output is textbrowser and the element name corresponding to the pushbutton button is calculated
3. Code Writing
#-*-coding:utf-8-*-__author__='Hzq'ImportSYS fromPyQt5ImportUIC, Qtwidgets (Form_class, Qtbase_class)= Uic.loaduitype ('Untitled.ui')classMainWindow (Form_class, qtbase_class):def __init__(self): Super ().__init__() self.setupui (self) self.pushButton.clicked.connect (self.addfunction)defaddfunction (self): a=Float (Self.textEdit.toPlainText ()) b=Float (Self.textEdit_2.toPlainText ()) C= A +b d= A-b self.textEdit_3.setText (str (c)) Self.textEdit_6.setText (str (d)) Self.textEdit_4.append ("%.2f +%.2f =%.2f"%(A, B, c)) Self.textEdit_5.append ("%.2f-%.2f =%.2f"%(A, B, D))if __name__=="__main__": App=Qtwidgets.qapplication (SYS.ARGV) UI=MainWindow () ui.show () Sys.exit (App.exec_ ())
4. Effect
Python PyQt5 making a simple calculator