Python PyQt5 making a simple calculator

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.