This article uses Qt4, is a python (x, y) suite of integrated, why not integrate Qt5 it, too lazy to install ah :)
text:
First look at the finished product:
The function of this program is to enter the original price and percentage of price, calculated the final price.
Designer section
Then is a development stage, first create a form in Qt Designer, the picture probably looks like, and then dragged into the controls
Among them, "the original price how much ah", "green label marked" These kind of control is the text QLabel , the first frame is QTextEdit , the second standard standard is QDoubleSpinBox , or use QSpinBox all, the two main types of digital s difference,
Submit button is QPushButton , here mainly want to try different controls, QLabel Next, click on the picture box, and then edit the properties will be in the name objectName labelResult , QTextEdit named textPrice, QDoubleSpinBox
Named dSBPer , the QPushButton named btnSub FIG:
This naming and no special meaning, so that I can just remember some of the more firmly, to prevent the program hit half back and forth to see the designer.
Here is a troublesome thing ------------ picture frame
Pictures show itself is QLabel, so you need to display pictures placed in the designer a QLbel control, change control does not change in the program, so the default name like, the next need to add the resource file in Explorer, as shown:
In Qt Designer, you can simply load the pixmap property QLabel controls, support files accessible Qt documentation, I'll post later in the article
It is worth noting that the resource file in the program needs to be compiled for the .py file
Compiled code as follows:
pyrcc4 -o a1_rc.py a1.qrc
Part of the program
Start now part of the editing program
The first step is to import about Qt library
Then create initialization Window
Next is the basis for the preparation of class
Where "self.btnSub.clicked.connect (self.CalculateTax)" in, btnSub is the name of the button, clicked.connect is connected to the function button click event to be executed, CalculateTax my own functions written in clicks, he will will be called after the button is clicked
This line main program is a program execution operation of the form
Then he began to write CalculateTax (self) function, and place it in App class:
"TextPrice.toPlainText ()" which is the name of the control textPrice, toPlainText () is a method of control, which is to get control of text, function specific detailed information can be queried in the Qt documentation, empathy behind the controls
Qt is little, if garbled Chinese, the Chinese need to specifying the encoding, if necessary to see the specific coding program, the code was added in this direct u string before transcoding.
Attached hereto is the official Qt documentation page:
http://doc.qt.io/qt-5/classes.html
Reproduced in: https: //www.jianshu.com/p/2d79399d46d0