pyqt5 pyqtdesigner的部署使用


推薦使用anaconda,里面直接就包含了qtdesigner

使用時直接在命令行輸入

open -a Designer
打開應用UI繪制界面

 

坑一:pip install pyqt5是不夠的!
除此之外你還需要pip install pyqt5-tools
最好的方法就是直接 pip install pyqt5 pyqt5-tools

坑二: pyrcc5.exe文件所在地方
也不知道是版本問題還是別的什么問題,它並不在網上的很多大神說的,在pyqt5-tools中,當然,在pyqt5中也沒有。其實,它被放在了Python\Python37\Scripts (注意那個37只是我的python的版本號而已)

對於Mac用戶

1. 從PyQt官網下載安裝dmg格式的安裝文件;
2. brew install pyqt5;
3. pip install pyqt5-macos-built

成都可能吃

你可能覺得網速跟不上經常出現timeout無法下載成功,那么建議使用鏡像源下載

比如

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyqt5

另外值得一提的是好像目前pyqt5-tools在Mac上面是沒有的,所以你可以將下面這個代碼和你的UI圖放在一個目錄里面,它可以將你的UI圖變成p y文件

import os
import os.path

dir = './'


def listUiFile():
    list = []
    files = os.listdir(dir)
    for filename in files:
        # print( dir + os.sep + f  )
        # print(filename)
        if os.path.splitext(filename)[1] == '.ui':
            list.append(filename)
    return list


def transPyFile(filename):
    return os.path.splitext(filename)[0] + '.py'


def runMain():
    list = listUiFile()
    for uifile in list:
        pyfile = transPyFile(uifile)
        cmd = 'pyuic5 -o {pyfile} {uifile}'.format(pyfile=pyfile, uifile=uifile)
        # print(cmd)
        os.system(cmd)


if __name__ == "__main__":
    runMain()

 





免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM