日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

[TimLinux] PyQt5 安装部署

發(fā)布時間:2024/8/26 linux 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [TimLinux] PyQt5 安装部署 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1. 依賴包

Click (7.0) PyQt5 (5.11.2) PyQt5-sip (4.19.12) QScintilla (2.10.7) pip (9.0.1) pyqt5-tools (5.11.2.1.3rc8) 提供了QtDesigner.exe工具 python-dotenv (0.9.1) setuptools (28.8.0) sip (4.19.8)

這些依賴包都能夠通過pip3 install *.whl 的包格式來安裝。

1.1. 安裝命令

PyQt5(不包含有 QtDesigner)

PS C:\Users\admin\Desktop> pip3 install PyQt5 -i https://pypi.douban.com/simple Looking in indexes: https://pypi.douban.com/simple Collecting PyQt5Downloading https://pypi.doubanio.com/packages/5d/85/d174a50e0d6b60aa9113f6a32afb31f2
5345bec8584992af486235373252/PyQt5-5.11.2-5.11.1-cp35.cp36.cp37.cp38-none-win_amd64.whl (93.3MB)100% |████████████████████████████████| 93.4MB 1.1MB/s Collecting PyQt5_sip<4.20,>=4.19.11 (from PyQt5)Downloading https://pypi.doubanio.com/packages/3f/4f/7b820770e6a8f8b83cacea561534e31c7
8a74eeac0fb2f7618c835fa74c6/PyQt5_sip-4.19.12-cp36-none-win_amd64.whl (51kB)100% |████████████████████████████████| 61kB 1.6MB/s Installing collected packages: PyQt5-sip, PyQt5 Successfully installed PyQt5-5.11.2 PyQt5-sip-4.19.12 PS C:\Users\admin\Desktop>

PyQt5-tools (包含有 QtDesigner)

PS C:\Users\admin\Desktop> pip3 install PyQt5-tools -i https://pypi.douban.com/simple Looking in indexes: https://pypi.douban.com/simple Collecting PyQt5-toolsDownloading https://pypi.doubanio.com/packages/0e/a1/b2bbbb9e0c0f374fb77c85b014fc39fdb
6e9e258c20906cc7ecb5f565e38/pyqt5_tools-5.9.0.1.2-cp36-none-win_amd64.whl (37.5MB)100% |████████████████████████████████| 37.5MB 6.6MB/s Installing collected packages: PyQt5-tools Successfully installed PyQt5-tools-5.9.0.1.2 PS C:\Users\admin\Desktop>

?1.2. 文檔API

https://pyqt.readthedocs.io/en/latest/sip-classes.html

https://riverbankcomputing.com/news -->?https://pyqt.readthedocs.io/en/latest/

?

2. PyCharm配置

請參考:https://www.cnblogs.com/BlueSkyyj/p/8398277.html

簡略步驟說明:

  • 添加 External Tools:QtDesigner
  • 添加 External Tools:PyUIC(QtDesigner生成的.ui文件自動轉換為.py文件)

2.1. External Tools: QtDesigner

Settings -> Tools -> External Tools 選中“+”,彈出的對話框:Name: QtDesigner Tool Settings:Program: C:\Python365\Lib\site-packages\pyqt5_tools\designer.exeParameters: $FileDir$ (這是一個宏,可以通過點擊Insert macro來添加這個值,手動輸入也是一樣的意思)Working directory: $FileDir$

?

?

2.2. External Tools: PyUIC

settings -> Tools -> External Tools 選中“+”,彈出的對話框:Name: PyUIC Tool settings:Program: C:\Python365\python.exeParameters: -m PyQt5.uic.pyuic $FileName$ -o $FileNameWithoutExtension$.pyWorking directory: $FileDir$ (可以通過 insert macro來設置,也可以手動輸入)

?

?

3. 示例

創(chuàng)建一個純python工程(Pure Python Project)QtTest。

3.1. 啟動QtDesigner.exe

通過右鍵 -> External Tools -> QtDesigner,將啟動QtDesigner.exe,創(chuàng)建一個MainWindow,然后將左側的一個 PushButton 拖入 創(chuàng)建的MainWindow,保存文件到工程目錄,取名 hello.ui

3.2. UI轉換為PY

選中 hello.ui,然后右鍵 -> External Tools -> PyUIC,將自動把 hello.ui 轉換為 hello.py 文件了。

3.3. 編寫 main.py

在工程目錄中創(chuàng)建 main.py 文件,寫入如下內容:

import sys import hello #生成的 hello.py from PyQt5.QtWidgets import QApplication, QMainWindowif __name__ == '__main__':app = QApplication(sys.argv)w = QMainWindow()ui = hello.Ui_MainWindow()ui.setUi(w)w.show()sys.exit(app.exec_())

3.4. 運行

main.py 文件內,點擊鼠標右鍵,選擇:Run,將彈出一個 Window 窗口。

3.5. 不啟動后臺

使用 pythonw.exe 運行 GUI 程序,將不顯示 cmd 窗口,只會顯示 GUI 窗口,這點非常的有用,但是這個解析器同時關閉了原來的:stdin, stdout, stderr。解決方案參考鏈接:https://stackoverflow.com/questions/9705982/pythonw-exe-or-python-exe

?3.6. 另外一個示例

# 來自 《PyQt5 快速開發(fā)與實踐》 import sys from PyQt5.QtWidgets import QPushButton, QApplication, QWidgetclass WinForm(QWidget):def __init__(self, parent=None):super(WinForm, self).__init__(parent)self.setGeometry(300, 300, 350, 350)self.setWindowTitle('點擊按鈕關閉窗口')quit = QPushButton('Close', self)quit.setGeometry(10, 10, 60, 35)quit.setStyleSheet("background-color: red")quit.clicked.connect(self.close)if __name__ == '__main__':app = QApplication(sys.argv)win = WinForm()win.show()sys.exit(app.exec_())

?

轉載于:https://www.cnblogs.com/timlinux/p/9712119.html

總結

以上是生活随笔為你收集整理的[TimLinux] PyQt5 安装部署的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。