[{"data":1,"prerenderedAt":999},["ShallowReactive",2],{"post-2025-07-16-pyqt5-pyqt5":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"tags":11,"body":15,"_type":993,"_id":994,"_source":995,"_file":996,"_stem":997,"_extension":998},"\u002Fblog\u002F2025-07-16-pyqt5-pyqt5","blog",false,"","PyQt5-环境搭建","PyQt5开发环境搭建教程，Python解释器、PyCharm编辑器与Qt模块安装配置。","2025-07-16",[12,13,14],"Python","PyQt5","GUI",{"type":16,"children":17,"toc":983},"root",[18,26,30,36,51,56,61,64,69,145,158,205,210,218,230,265,286,341,346,355,406,414,422,429,434,454,462,518,526,534,583,591,599,612,617,620,627,632,640,653,661,666,674,679,687,692,697,705,718,870,875,883,888,893,901,906,924,951,964,969,972,977],{"type":19,"tag":20,"props":21,"children":23},"element","h2",{"id":22},"软件安装",[24],{"type":25,"value":22},"text",{"type":19,"tag":27,"props":28,"children":29},"hr",{},[],{"type":19,"tag":31,"props":32,"children":33},"p",{},[34],{"type":25,"value":35},"目标软件：",{"type":19,"tag":37,"props":38,"children":39},"ul",{},[40,46],{"type":19,"tag":41,"props":42,"children":43},"li",{},[44],{"type":25,"value":45},"Python解释器",{"type":19,"tag":41,"props":47,"children":48},{},[49],{"type":25,"value":50},"Pycharm编辑器",{"type":19,"tag":31,"props":52,"children":53},{},[54],{"type":25,"value":55},"安装教程前往：Python安装（请参考Python官方文档）",{"type":19,"tag":20,"props":57,"children":59},{"id":58},"环境搭建",[60],{"type":25,"value":58},{"type":19,"tag":27,"props":62,"children":63},{},[],{"type":19,"tag":31,"props":65,"children":66},{},[67],{"type":25,"value":68},"搭建完成后最终的环境详情：",{"type":19,"tag":70,"props":71,"children":75},"pre",{"code":72,"language":73,"meta":7,"className":74,"style":7},"python安装路径：D:\\ProgramEnviron\\Python\\Python311\n\nPython 3.13.2\npip 25.1.1\n\nPyQt5 5.15.11\nqt5_applications 5.15.2.2.3\n","2025-7-21","language-2025-7-21 shiki shiki-themes github-dark",[76],{"type":19,"tag":77,"props":78,"children":79},"code",{"__ignoreMap":7},[80,91,101,110,119,127,136],{"type":19,"tag":81,"props":82,"children":85},"span",{"class":83,"line":84},"line",1,[86],{"type":19,"tag":81,"props":87,"children":88},{},[89],{"type":25,"value":90},"python安装路径：D:\\ProgramEnviron\\Python\\Python311\n",{"type":19,"tag":81,"props":92,"children":94},{"class":83,"line":93},2,[95],{"type":19,"tag":81,"props":96,"children":98},{"emptyLinePlaceholder":97},true,[99],{"type":25,"value":100},"\n",{"type":19,"tag":81,"props":102,"children":104},{"class":83,"line":103},3,[105],{"type":19,"tag":81,"props":106,"children":107},{},[108],{"type":25,"value":109},"Python 3.13.2\n",{"type":19,"tag":81,"props":111,"children":113},{"class":83,"line":112},4,[114],{"type":19,"tag":81,"props":115,"children":116},{},[117],{"type":25,"value":118},"pip 25.1.1\n",{"type":19,"tag":81,"props":120,"children":122},{"class":83,"line":121},5,[123],{"type":19,"tag":81,"props":124,"children":125},{"emptyLinePlaceholder":97},[126],{"type":25,"value":100},{"type":19,"tag":81,"props":128,"children":130},{"class":83,"line":129},6,[131],{"type":19,"tag":81,"props":132,"children":133},{},[134],{"type":25,"value":135},"PyQt5 5.15.11\n",{"type":19,"tag":81,"props":137,"children":139},{"class":83,"line":138},7,[140],{"type":19,"tag":81,"props":141,"children":142},{},[143],{"type":25,"value":144},"qt5_applications 5.15.2.2.3\n",{"type":19,"tag":31,"props":146,"children":147},{},[148,150,156],{"type":25,"value":149},"1）首先配置一下",{"type":19,"tag":77,"props":151,"children":153},{"className":152},[],[154],{"type":25,"value":155},"pip",{"type":25,"value":157},"的默认镜像资源，它可以有效的提高效率，否则下载速度将会很慢。配置语法及配置命令如下：",{"type":19,"tag":70,"props":159,"children":163},{"code":160,"language":161,"meta":7,"className":162,"style":7},"# pip config set global.index-url 镜像源地址\npip config set global.index-url https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n","shell","language-shell shiki shiki-themes github-dark",[164],{"type":19,"tag":77,"props":165,"children":166},{"__ignoreMap":7},[167,176],{"type":19,"tag":81,"props":168,"children":169},{"class":83,"line":84},[170],{"type":19,"tag":81,"props":171,"children":173},{"style":172},"--shiki-default:#6A737D",[174],{"type":25,"value":175},"# pip config set global.index-url 镜像源地址\n",{"type":19,"tag":81,"props":177,"children":178},{"class":83,"line":93},[179,184,190,195,200],{"type":19,"tag":81,"props":180,"children":182},{"style":181},"--shiki-default:#B392F0",[183],{"type":25,"value":155},{"type":19,"tag":81,"props":185,"children":187},{"style":186},"--shiki-default:#9ECBFF",[188],{"type":25,"value":189}," config",{"type":19,"tag":81,"props":191,"children":192},{"style":186},[193],{"type":25,"value":194}," set",{"type":19,"tag":81,"props":196,"children":197},{"style":186},[198],{"type":25,"value":199}," global.index-url",{"type":19,"tag":81,"props":201,"children":202},{"style":186},[203],{"type":25,"value":204}," https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n",{"type":19,"tag":31,"props":206,"children":207},{},[208],{"type":25,"value":209},"使用国内的各大镜像源进行下载，下载速度快！",{"type":19,"tag":70,"props":211,"children":213},{"code":212},"清华大学镜像：https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n阿里云镜像：https:\u002F\u002Fmirrors.aliyun.com\u002Fpypi\u002Fsimple\u002F\n中科大镜像：https:\u002F\u002Fpypi.mirrors.ustc.edu.cn\u002Fsimple\u002F\n...\n",[214],{"type":19,"tag":77,"props":215,"children":216},{"__ignoreMap":7},[217],{"type":25,"value":212},{"type":19,"tag":31,"props":219,"children":220},{},[221,223,228],{"type":25,"value":222},"2）对",{"type":19,"tag":77,"props":224,"children":226},{"className":225},[],[227],{"type":25,"value":155},{"type":25,"value":229},"进行升级，在终端执行下列命令：",{"type":19,"tag":70,"props":231,"children":233},{"code":232,"language":161,"meta":7,"className":162,"style":7},"pip install --upgrade pip #（或者pip install -U pip）\n",[234],{"type":19,"tag":77,"props":235,"children":236},{"__ignoreMap":7},[237],{"type":19,"tag":81,"props":238,"children":239},{"class":83,"line":84},[240,244,249,255,260],{"type":19,"tag":81,"props":241,"children":242},{"style":181},[243],{"type":25,"value":155},{"type":19,"tag":81,"props":245,"children":246},{"style":186},[247],{"type":25,"value":248}," install",{"type":19,"tag":81,"props":250,"children":252},{"style":251},"--shiki-default:#79B8FF",[253],{"type":25,"value":254}," --upgrade",{"type":19,"tag":81,"props":256,"children":257},{"style":186},[258],{"type":25,"value":259}," pip",{"type":19,"tag":81,"props":261,"children":262},{"style":172},[263],{"type":25,"value":264}," #（或者pip install -U pip）\n",{"type":19,"tag":31,"props":266,"children":267},{},[268,270,276,278,284],{"type":25,"value":269},"3）接下来安装PyQt5的环境，一共需要安装两个包，分别是",{"type":19,"tag":77,"props":271,"children":273},{"className":272},[],[274],{"type":25,"value":275},"pyqt5",{"type":25,"value":277},"和",{"type":19,"tag":77,"props":279,"children":281},{"className":280},[],[282],{"type":25,"value":283},"qt5_applications",{"type":25,"value":285},"，具体命令如下：",{"type":19,"tag":70,"props":287,"children":289},{"code":288,"language":161,"meta":7,"className":162,"style":7},"# 安装qt环境\npip install pyqt5\n# 安装qt相关环境，如designer、pyuic、pyrcc...都包含在qt5_applications内\npip install qt5_applications\n",[290],{"type":19,"tag":77,"props":291,"children":292},{"__ignoreMap":7},[293,301,317,325],{"type":19,"tag":81,"props":294,"children":295},{"class":83,"line":84},[296],{"type":19,"tag":81,"props":297,"children":298},{"style":172},[299],{"type":25,"value":300},"# 安装qt环境\n",{"type":19,"tag":81,"props":302,"children":303},{"class":83,"line":93},[304,308,312],{"type":19,"tag":81,"props":305,"children":306},{"style":181},[307],{"type":25,"value":155},{"type":19,"tag":81,"props":309,"children":310},{"style":186},[311],{"type":25,"value":248},{"type":19,"tag":81,"props":313,"children":314},{"style":186},[315],{"type":25,"value":316}," pyqt5\n",{"type":19,"tag":81,"props":318,"children":319},{"class":83,"line":103},[320],{"type":19,"tag":81,"props":321,"children":322},{"style":172},[323],{"type":25,"value":324},"# 安装qt相关环境，如designer、pyuic、pyrcc...都包含在qt5_applications内\n",{"type":19,"tag":81,"props":326,"children":327},{"class":83,"line":112},[328,332,336],{"type":19,"tag":81,"props":329,"children":330},{"style":181},[331],{"type":25,"value":155},{"type":19,"tag":81,"props":333,"children":334},{"style":186},[335],{"type":25,"value":248},{"type":19,"tag":81,"props":337,"children":338},{"style":186},[339],{"type":25,"value":340}," qt5_applications\n",{"type":19,"tag":31,"props":342,"children":343},{},[344],{"type":25,"value":345},"4）通过安装的qt5_application添加外部工具，下图是打开添加外部工具步骤：",{"type":19,"tag":31,"props":347,"children":348},{},[349],{"type":19,"tag":350,"props":351,"children":354},"img",{"alt":352,"src":353},"Pasted image 20250722093200","\u002Fimages\u002Fblog\u002Fpyqt5\u002FPasted%20image%2020250722093200.png",[],{"type":19,"tag":31,"props":356,"children":357},{},[358,360,366,368,374,376,381,383,388,390,396,398,404],{"type":25,"value":359},"5）首先添加",{"type":19,"tag":77,"props":361,"children":363},{"className":362},[],[364],{"type":25,"value":365},"Qt Designer",{"type":25,"value":367},"设计师，在打开的",{"type":19,"tag":77,"props":369,"children":371},{"className":370},[],[372],{"type":25,"value":373},"Create Tool",{"type":25,"value":375},"窗口填写信息，名称填写为",{"type":19,"tag":77,"props":377,"children":379},{"className":378},[],[380],{"type":25,"value":365},{"type":25,"value":382},"，程序选择刚才安装的",{"type":19,"tag":77,"props":384,"children":386},{"className":385},[],[387],{"type":25,"value":283},{"type":25,"value":389},"模块的路径下的",{"type":19,"tag":77,"props":391,"children":393},{"className":392},[],[394],{"type":25,"value":395},"Qt\\bin\\designer.exe",{"type":25,"value":397},"，此项参数为空，工作目录为默认。完成后点击",{"type":19,"tag":77,"props":399,"children":401},{"className":400},[],[402],{"type":25,"value":403},"OK",{"type":25,"value":405},"即可；",{"type":19,"tag":70,"props":407,"children":409},{"code":408},"参数设置:\nName: Qt Designer\nProgram: D:\\ProgramEnviron\\Python\\Python311\\Lib\\site-packages\\qt5_applications\\Qt\\bin\\designer.exe\nArguments: \nWorking directory: D:\\ProgramEnviron\\Python\\Python311\\Lib\\site-packages\\qt5_applications\\Qt\\bin\n",[410],{"type":19,"tag":77,"props":411,"children":412},{"__ignoreMap":7},[413],{"type":25,"value":408},{"type":19,"tag":31,"props":415,"children":416},{},[417],{"type":19,"tag":350,"props":418,"children":421},{"alt":419,"src":420},"Pasted image 20250722094032","\u002Fimages\u002Fblog\u002Fpyqt5\u002FPasted%20image%2020250722094032.png",[],{"type":19,"tag":423,"props":424,"children":426},"font",{"color":425},"red",[427],{"type":25,"value":428},"\n注意：此处的程序路径填写时是在自己本机的路径下找，以上是根据我的路径进行查找的，只需找到Python的安装路径就可以确定程序的路径了，程序路径位于Python路径下的 .\\Lib\\site-packages\\qt5_applications\\Qt\\bin\\designer.exe \n",{"type":19,"tag":31,"props":430,"children":431},{},[432],{"type":25,"value":433},"可以通过终端进行对Python路径的查找，打开终端输入下列命令：",{"type":19,"tag":70,"props":435,"children":437},{"code":436,"language":161,"meta":7,"className":162,"style":7},"where python\n",[438],{"type":19,"tag":77,"props":439,"children":440},{"__ignoreMap":7},[441],{"type":19,"tag":81,"props":442,"children":443},{"class":83,"line":84},[444,449],{"type":19,"tag":81,"props":445,"children":446},{"style":181},[447],{"type":25,"value":448},"where",{"type":19,"tag":81,"props":450,"children":451},{"style":186},[452],{"type":25,"value":453}," python\n",{"type":19,"tag":31,"props":455,"children":456},{},[457],{"type":19,"tag":350,"props":458,"children":461},{"alt":459,"src":460},"Pasted image 20250722100029","\u002Fimages\u002Fblog\u002Fpyqt5\u002FPasted%20image%2020250722100029.png",[],{"type":19,"tag":31,"props":463,"children":464},{},[465,467,473,475,480,481,486,488,494,496,502,504,510,512,517],{"type":25,"value":466},"6）然后添加",{"type":19,"tag":77,"props":468,"children":470},{"className":469},[],[471],{"type":25,"value":472},"pyuic",{"type":25,"value":474},"工具，在打开的",{"type":19,"tag":77,"props":476,"children":478},{"className":477},[],[479],{"type":25,"value":373},{"type":25,"value":375},{"type":19,"tag":77,"props":482,"children":484},{"className":483},[],[485],{"type":25,"value":472},{"type":25,"value":487},"，程序选择Python路径下的",{"type":19,"tag":77,"props":489,"children":491},{"className":490},[],[492],{"type":25,"value":493},"D:\\ProgramEnviron\\Python\\Python311\\python.exe",{"type":25,"value":495},"，此项参数为",{"type":19,"tag":77,"props":497,"children":499},{"className":498},[],[500],{"type":25,"value":501},"-m PyQt5.uic.pyuic $FileName$ -o $FileNameWithoutExtension$.py",{"type":25,"value":503},"，工作目录为",{"type":19,"tag":77,"props":505,"children":507},{"className":506},[],[508],{"type":25,"value":509},"$FileDir$",{"type":25,"value":511},"。完成后点击",{"type":19,"tag":77,"props":513,"children":515},{"className":514},[],[516],{"type":25,"value":403},{"type":25,"value":405},{"type":19,"tag":70,"props":519,"children":521},{"code":520},"参数设置:\nName: Pyuic\nProgram: D:\\ProgramEnviron\\Python\\Python311\\python.exe\nArguments: -m PyQt5.uic.pyuic $FileName$ -o $FileNameWithoutExtension$.py\nWorking directory: $FileDir$\n",[522],{"type":19,"tag":77,"props":523,"children":524},{"__ignoreMap":7},[525],{"type":25,"value":520},{"type":19,"tag":31,"props":527,"children":528},{},[529],{"type":19,"tag":350,"props":530,"children":533},{"alt":531,"src":532},"Pasted image 20250722100951","\u002Fimages\u002Fblog\u002Fpyqt5\u002FPasted%20image%2020250722100951.png",[],{"type":19,"tag":31,"props":535,"children":536},{},[537,539,545,546,551,552,557,558,563,564,570,571,576,577,582],{"type":25,"value":538},"7）然后添加",{"type":19,"tag":77,"props":540,"children":542},{"className":541},[],[543],{"type":25,"value":544},"pyrcc",{"type":25,"value":474},{"type":19,"tag":77,"props":547,"children":549},{"className":548},[],[550],{"type":25,"value":373},{"type":25,"value":375},{"type":19,"tag":77,"props":553,"children":555},{"className":554},[],[556],{"type":25,"value":544},{"type":25,"value":487},{"type":19,"tag":77,"props":559,"children":561},{"className":560},[],[562],{"type":25,"value":493},{"type":25,"value":495},{"type":19,"tag":77,"props":565,"children":567},{"className":566},[],[568],{"type":25,"value":569},"-m PyQt5.pyrcc_main $FileName$ -o $FileNameWithoutExtension$_rc.py",{"type":25,"value":503},{"type":19,"tag":77,"props":572,"children":574},{"className":573},[],[575],{"type":25,"value":509},{"type":25,"value":511},{"type":19,"tag":77,"props":578,"children":580},{"className":579},[],[581],{"type":25,"value":403},{"type":25,"value":405},{"type":19,"tag":70,"props":584,"children":586},{"code":585},"参数设置:\nName: Pyrcc\nProgram: D:\\ProgramEnviron\\Python\\Python311\\python.exe\nArguments: -m PyQt5.pyrcc_main $FileName$ -o $FileNameWithoutExtension$_rc.py\nWorking directory: $FileDir$\n",[587],{"type":19,"tag":77,"props":588,"children":589},{"__ignoreMap":7},[590],{"type":25,"value":585},{"type":19,"tag":31,"props":592,"children":593},{},[594],{"type":19,"tag":350,"props":595,"children":598},{"alt":596,"src":597},"Pasted image 20250722101054","\u002Fimages\u002Fblog\u002Fpyqt5\u002FPasted%20image%2020250722101054.png",[],{"type":19,"tag":31,"props":600,"children":601},{},[602,604,610],{"type":25,"value":603},"等上述三个工具全部设置完成后，我们就相当于Qt5的环境设置完成了，点击",{"type":19,"tag":77,"props":605,"children":607},{"className":606},[],[608],{"type":25,"value":609},"Apply",{"type":25,"value":611},"应用工具。",{"type":19,"tag":20,"props":613,"children":615},{"id":614},"验证环境",[616],{"type":25,"value":614},{"type":19,"tag":27,"props":618,"children":619},{},[],{"type":19,"tag":621,"props":622,"children":624},"h3",{"id":623},"验证qt-designer",[625],{"type":25,"value":626},"验证Qt Designer",{"type":19,"tag":31,"props":628,"children":629},{},[630],{"type":25,"value":631},"1）依次点击 Tools --> External Tools(外部工具) --> Qt Designer 打开设计师，进入设计师主界面，如下图所示：",{"type":19,"tag":31,"props":633,"children":634},{},[635],{"type":19,"tag":350,"props":636,"children":639},{"alt":637,"src":638},"Pasted image 20250722101659","\u002Fimages\u002Fblog\u002Fpyqt5\u002FPasted%20image%2020250722101659.png",[],{"type":19,"tag":31,"props":641,"children":642},{},[643,645,651],{"type":25,"value":644},"2）在打开的设计师界面选择",{"type":19,"tag":77,"props":646,"children":648},{"className":647},[],[649],{"type":25,"value":650},"MainWindow",{"type":25,"value":652},"窗体，点击创建，如下图：",{"type":19,"tag":31,"props":654,"children":655},{},[656],{"type":19,"tag":350,"props":657,"children":660},{"alt":658,"src":659},"Pasted image 20250722102048","\u002Fimages\u002Fblog\u002Fpyqt5\u002FPasted%20image%2020250722102048.png",[],{"type":19,"tag":31,"props":662,"children":663},{},[664],{"type":25,"value":665},"3）接下来对界面进行设计，例如我设置一个简单的登录界面，如下图：",{"type":19,"tag":31,"props":667,"children":668},{},[669],{"type":19,"tag":350,"props":670,"children":673},{"alt":671,"src":672},"Pasted image 20250722102705","\u002Fimages\u002Fblog\u002Fpyqt5\u002FPasted%20image%2020250722102705.png",[],{"type":19,"tag":31,"props":675,"children":676},{},[677],{"type":25,"value":678},"4）在设计完成后保存ui文件，记住自己的路径选择，后续要用，图示如下：",{"type":19,"tag":31,"props":680,"children":681},{},[682],{"type":19,"tag":350,"props":683,"children":686},{"alt":684,"src":685},"Pasted image 20250722103326","\u002Fimages\u002Fblog\u002Fpyqt5\u002FPasted%20image%2020250722103326.png",[],{"type":19,"tag":621,"props":688,"children":690},{"id":689},"验证pyuic",[691],{"type":25,"value":689},{"type":19,"tag":31,"props":693,"children":694},{},[695],{"type":25,"value":696},"1）将刚才保存的ui文件找到，使用Pycharm打开，在Pycharm界面资源管理器中找到该ui文件，右击选择 External Tools(外部工具) --> pyuic，点击完成后便会生成当前的ui文件的Python代码。如下图所示：",{"type":19,"tag":31,"props":698,"children":699},{},[700],{"type":19,"tag":350,"props":701,"children":704},{"alt":702,"src":703},"Pasted image 20250722104742","\u002Fimages\u002Fblog\u002Fpyqt5\u002FPasted%20image%2020250722104742.png",[],{"type":19,"tag":31,"props":706,"children":707},{},[708,710,716],{"type":25,"value":709},"2）可以新建一个",{"type":19,"tag":77,"props":711,"children":713},{"className":712},[],[714],{"type":25,"value":715},"main.py",{"type":25,"value":717},"文件来表示主文件，在该文件内添加如下代码（确保该文件与生成的ui的python在同一目录下）：",{"type":19,"tag":70,"props":719,"children":723},{"code":720,"language":721,"meta":7,"className":722,"style":7},"import sys  \n  \nfrom PyQt5.QtWidgets import QMainWindow, QApplication  \nfrom untitled import Ui_MainWindow  \n  \n  \nclass windows(QMainWindow, Ui_MainWindow):  \n    def __init__(self):  \n        super(windows, self).__init__()  \n        self.setupUi(self)  \n  \n# 格式化代码 ctrl + alt + L\nif __name__ == \"__main__\":  \n    app = QApplication(sys.argv)  \n    ui = windows()  \n    ui.show()  \n    app.exec_()\n","python","language-python shiki shiki-themes github-dark",[724],{"type":19,"tag":77,"props":725,"children":726},{"__ignoreMap":7},[727,735,743,751,759,766,773,781,790,799,808,816,825,834,843,852,861],{"type":19,"tag":81,"props":728,"children":729},{"class":83,"line":84},[730],{"type":19,"tag":81,"props":731,"children":732},{},[733],{"type":25,"value":734},"import sys  \n",{"type":19,"tag":81,"props":736,"children":737},{"class":83,"line":93},[738],{"type":19,"tag":81,"props":739,"children":740},{},[741],{"type":25,"value":742},"  \n",{"type":19,"tag":81,"props":744,"children":745},{"class":83,"line":103},[746],{"type":19,"tag":81,"props":747,"children":748},{},[749],{"type":25,"value":750},"from PyQt5.QtWidgets import QMainWindow, QApplication  \n",{"type":19,"tag":81,"props":752,"children":753},{"class":83,"line":112},[754],{"type":19,"tag":81,"props":755,"children":756},{},[757],{"type":25,"value":758},"from untitled import Ui_MainWindow  \n",{"type":19,"tag":81,"props":760,"children":761},{"class":83,"line":121},[762],{"type":19,"tag":81,"props":763,"children":764},{},[765],{"type":25,"value":742},{"type":19,"tag":81,"props":767,"children":768},{"class":83,"line":129},[769],{"type":19,"tag":81,"props":770,"children":771},{},[772],{"type":25,"value":742},{"type":19,"tag":81,"props":774,"children":775},{"class":83,"line":138},[776],{"type":19,"tag":81,"props":777,"children":778},{},[779],{"type":25,"value":780},"class windows(QMainWindow, Ui_MainWindow):  \n",{"type":19,"tag":81,"props":782,"children":784},{"class":83,"line":783},8,[785],{"type":19,"tag":81,"props":786,"children":787},{},[788],{"type":25,"value":789},"    def __init__(self):  \n",{"type":19,"tag":81,"props":791,"children":793},{"class":83,"line":792},9,[794],{"type":19,"tag":81,"props":795,"children":796},{},[797],{"type":25,"value":798},"        super(windows, self).__init__()  \n",{"type":19,"tag":81,"props":800,"children":802},{"class":83,"line":801},10,[803],{"type":19,"tag":81,"props":804,"children":805},{},[806],{"type":25,"value":807},"        self.setupUi(self)  \n",{"type":19,"tag":81,"props":809,"children":811},{"class":83,"line":810},11,[812],{"type":19,"tag":81,"props":813,"children":814},{},[815],{"type":25,"value":742},{"type":19,"tag":81,"props":817,"children":819},{"class":83,"line":818},12,[820],{"type":19,"tag":81,"props":821,"children":822},{},[823],{"type":25,"value":824},"# 格式化代码 ctrl + alt + L\n",{"type":19,"tag":81,"props":826,"children":828},{"class":83,"line":827},13,[829],{"type":19,"tag":81,"props":830,"children":831},{},[832],{"type":25,"value":833},"if __name__ == \"__main__\":  \n",{"type":19,"tag":81,"props":835,"children":837},{"class":83,"line":836},14,[838],{"type":19,"tag":81,"props":839,"children":840},{},[841],{"type":25,"value":842},"    app = QApplication(sys.argv)  \n",{"type":19,"tag":81,"props":844,"children":846},{"class":83,"line":845},15,[847],{"type":19,"tag":81,"props":848,"children":849},{},[850],{"type":25,"value":851},"    ui = windows()  \n",{"type":19,"tag":81,"props":853,"children":855},{"class":83,"line":854},16,[856],{"type":19,"tag":81,"props":857,"children":858},{},[859],{"type":25,"value":860},"    ui.show()  \n",{"type":19,"tag":81,"props":862,"children":864},{"class":83,"line":863},17,[865],{"type":19,"tag":81,"props":866,"children":867},{},[868],{"type":25,"value":869},"    app.exec_()\n",{"type":19,"tag":31,"props":871,"children":872},{},[873],{"type":25,"value":874},"3）添加完成后可以执行当前代码，发现运行结果与之前的设计器的效果相同，如下图：",{"type":19,"tag":31,"props":876,"children":877},{},[878],{"type":19,"tag":350,"props":879,"children":882},{"alt":880,"src":881},"Pasted image 20250722105335","\u002Fimages\u002Fblog\u002Fpyqt5\u002FPasted%20image%2020250722105335.png",[],{"type":19,"tag":621,"props":884,"children":886},{"id":885},"验证pyrcc",[887],{"type":25,"value":885},{"type":19,"tag":31,"props":889,"children":890},{},[891],{"type":25,"value":892},"1）重新打开Qt Designer设计师，打开之前保存的ui文件，如下图：",{"type":19,"tag":31,"props":894,"children":895},{},[896],{"type":19,"tag":350,"props":897,"children":900},{"alt":898,"src":899},"Pasted image 20250722165234","\u002Fimages\u002Fblog\u002Fpyqt5\u002FPasted%20image%2020250722165234.png",[],{"type":19,"tag":31,"props":902,"children":903},{},[904],{"type":25,"value":905},"2）为该ui界面添加一个图片，成功添加后保存，如下图：",{"type":19,"tag":31,"props":907,"children":908},{},[909,914,919],{"type":19,"tag":350,"props":910,"children":913},{"alt":911,"src":912},"Pasted image 20250722165825","\u002Fimages\u002Fblog\u002Fpyqt5\u002FPasted%20image%2020250722165825.png",[],{"type":19,"tag":350,"props":915,"children":918},{"alt":916,"src":917},"Pasted image 20250722170826","\u002Fimages\u002Fblog\u002Fpyqt5\u002FPasted%20image%2020250722170826.png",[],{"type":19,"tag":350,"props":920,"children":923},{"alt":921,"src":922},"Pasted image 20250722171251","\u002Fimages\u002Fblog\u002Fpyqt5\u002FPasted%20image%2020250722171251.png",[],{"type":19,"tag":31,"props":925,"children":926},{},[927,929,934,936,942,944,949],{"type":25,"value":928},"3）效果图如下，点击保存，然后再次回到Pycharm进行",{"type":19,"tag":77,"props":930,"children":932},{"className":931},[],[933],{"type":25,"value":472},{"type":25,"value":935},"转换，这时会比之前多出一个",{"type":19,"tag":77,"props":937,"children":939},{"className":938},[],[940],{"type":25,"value":941},".qrc",{"type":25,"value":943},"文件，在该",{"type":19,"tag":77,"props":945,"children":947},{"className":946},[],[948],{"type":25,"value":941},{"type":25,"value":950},"文件右击选择 External Tools(外部工具) --> pyrcc 进行转化，可以得到一个python文件。",{"type":19,"tag":31,"props":952,"children":953},{},[954,959],{"type":19,"tag":350,"props":955,"children":958},{"alt":956,"src":957},"Pasted image 20250722171752","\u002Fimages\u002Fblog\u002Fpyqt5\u002FPasted%20image%2020250722171752.png",[],{"type":19,"tag":350,"props":960,"children":963},{"alt":961,"src":962},"Pasted image 20250722172351","\u002Fimages\u002Fblog\u002Fpyqt5\u002FPasted%20image%2020250722172351.png",[],{"type":19,"tag":20,"props":965,"children":967},{"id":966},"结尾",[968],{"type":25,"value":966},{"type":19,"tag":27,"props":970,"children":971},{},[],{"type":19,"tag":31,"props":973,"children":974},{},[975],{"type":25,"value":976},"至此，若根据上述操作能够成功验证三个工具，那我们的PyQt5的PyCharm环境就搭建完成了，接下来开启Qt5之旅吧！",{"type":19,"tag":978,"props":979,"children":980},"style",{},[981],{"type":25,"value":982},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":7,"searchDepth":93,"depth":93,"links":984},[985,986,987,992],{"id":22,"depth":93,"text":22},{"id":58,"depth":93,"text":58},{"id":614,"depth":93,"text":614,"children":988},[989,990,991],{"id":623,"depth":103,"text":626},{"id":689,"depth":103,"text":689},{"id":885,"depth":103,"text":885},{"id":966,"depth":93,"text":966},"markdown","content:blog:2025-07-16-pyqt5-PyQt5环境搭建.md","content","blog\u002F2025-07-16-pyqt5-PyQt5环境搭建.md","blog\u002F2025-07-16-pyqt5-PyQt5环境搭建","md",1780801018285]