环境:Pycharm IDE+PtQT+Qt designer
需要安装python下qt的环境及工具,终端terminal下面运行指令,我这里已经安装,所以显示已经有了,两个都需要安装,需要记住安装的位置,一会儿需要设置环境变量。
pip install PyQt5
pip install PyQt5-tools
(DemoProject) E:\WorkSpace\BT\DemoProject>pip install PyQt5
Requirement already satisfied: PyQt5 in c:\users\guoqing.zhang\appdata\local\programs\python\python37\lib\site-packages (5.1
5.2)
Requirement already satisfied: PyQt5-sip<13,>=12.8 in c:\users\guoqing.zhang\appdata\local\programs\python\python37\lib\site
-packages (from PyQt5) (12.8.1)
配置qt designer.exe环境变量,根据自己安装的目录选择 目录:C:\Users\guoqing.zhang\AppData\Local\Programs\Python\Python37\Lib\site-packages\qt5_applications\Qt\bin
打开Pycharm,点击File-->Setting-->Tools-->External Tools,选择+号新建,第一个是qt designer,program为路径,arguments不填,working directory 为工作路径,填 $ FileDir $,为当前工作目录,这个工具可以直接打开qt designer(qt 设计师)。
第二个是PyUIC,program为python路径,arguments 填:-m PyQt5.uic.pyuic $ FileName $ -o $FileName,可以将UI文件转换为python代码,注意FileName前后没有空格。
- 可以使用代码进行绘制
self.Seed = QLineEdit()
self.DescriptionSeed = QLabel()
self.Key = QLineEdit()
self.DescriptionKey = QLabel()
self.DescriptionSeed.setText('Seed')
self.DescriptionKey.setText('Key')
self.Seed.setFixedWidth(200)
self.Seed.setFixedHeight(25)
self.Key.setFixedHeight(25)
self.Key.setFixedWidth(200)
self.Seed.setPlaceholderText('例如:0D 4A 1F FE')
几个函数介绍一下
- setFixedSize,设置控件大小
- QHBoxLayout,QVBoxLayout,控件横纵摆放函数
- addWidget,添加控件函数
- addLayout,添加布局函数
- QGroupBox,管理布局的组管理函数
- setLayout,设置布局,就可以显示出控件
- 也可以直接使用qt designer 进行绘制
终端 terminal 下面运行指令: pyinstaller -F -w win.py, 运行完成之后,工程目录中会有dist的文件夹,里面有exe问可执行文件。
碰到的问题:Pycharm 右键菜单选项里面没有external tools
解决办法:复制Link或者path(如下图所示),然后到IDE界面显示工程文件的区域粘贴,反复尝试几次,然后重新打开就有了
- 项目作者:ZGQ
- 邮箱:[email protected]
- 开发环境:PtQT5 版本5..15,Qt_Designer,Python 3.7
- 适用平台:WIndow