Reference link :https://blog.csdn.net/AzureMouse/article/details/90338961
install PyQt5
pip install PyQt5
pip install pyqt5-tools
The input terminal pyuic5
Output “Error: one input ui-file must be specified”, Successful installation
PyQt Based on learning
1.main window Create main window
2.Widget Box Free drag components
3. Based on learning
To add text Label
Add a button PushButton
Modify the window title windowTitle
preview Form > Preview / Preview in
preservation
Generate python Code
Use cmd Cut the directory to D Disk and execute the following command . Please send the following command to name Replace with file name
1.cd /d D:\AI\PyMyWork\UI
2.pyuic5 -o name.py name.ui
function Python Code
You need to re create a main.py The program is run by .ui Converted .py file
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
import gui_file_name
if __name__ == '__main__':
app = QApplication(sys.argv)
MainWindow = QMainWindow()
ui = gui_file_name.Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
Function is introduced
1. The use of buttons PushButton
Get button's ID
ObjectName:PushButton
Set trigger
Directly in “main.py” in “MainWindow.show()” Add the following line of code after
ui.pushButton.clicked.connect(click_success)
# pushButton It is the button just obtained id
# clicked It's a signal , Because it's clicking , So we use clicked
# click_success It corresponds to the slot to be called , Note that the function here is not written as click_success()
Set function
stay main.py Define a click_success, Used to trigger buttons
function
The console will display the results
Generate executable files (.exe)pip install pyinstaller
Open... After installation CMD then cd To the folder where the program is located , Input pyinstaller -F -w main.py
# Find... In the folder where the code is located dist Folder , In this folder exe Software , Double click to open it .
# In command -w It means : Direct release exe Application with command line debugging window , Add... To the instruction -w Commands can be masked
# In command -F It means : Use -F Instructions can package an application into a separate exe file , Otherwise it's one with all kinds of dll And folders that depend on files
4. Case study 1:GUI Exchange rate converter
partial(function, arg1, arg2, ......)
from functools import partial
ui.pushButton.clicked.connect(partial(convert, ui))
def convert(ui):
input = ui.lineEdit.text()
result = float(input) * 6.7
ui.lineEdit_2.setText(str(result))
5. Related learning Links
6. Use it directly pycharm convert to python Program
https://www.py.cn/jishu/gaoji/18503.html
Catalog One 、 Two 、python Inp
Similar to human eyes and brai