持续创作,加速成长!这是我参与「掘金日新计划 · 6 月更文挑战」的第13天,点击查看活动详情 VsCode开发基于Python的界面程序,我们会用到PYQT框架,是基于qt的一个Ui框架,适用于Python 首先pip install PyQt5/pip install pyqt5-tools 安装 PyQt5 和 pyqt5-tools
pip install PyQt5
pip install pyqt5-tools
-
vscode再安装PYQT Integration插件,该插件是开发PYQT的
-
VsCode中设置配置 界面pyqt程序
- Qtdesigner:Path ,一般是在你安装的python环境下的\Lib\site-packages\qt5_applications\Qt\bin\designer.exe
注意新版designer.exe不是在目录pyqt5_tools下而是qt5_applications目录下
-
在vscode中右键项目,新建一个界面配置
-
创建新窗体
-
创建完成
- 我们可以拖拽各种需要的控件,进行页面布局
- 点击保存,会生成一个U_Test.UI文件
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>270</x>
<y>300</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>270</x>
<y>60</y>
<width>54</width>
<height>12</height>
</rect>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
<widget class="QTextBrowser" name="textBrowser">
<property name="geometry">
<rect>
<x>270</x>
<y>90</y>
<width>256</width>
<height>192</height>
</rect>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>23</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
- 点击compile form,生成一个Ui_U_Test.py的文件,用于编写按钮,文本的的控制和处理代码
- 对于已经写好的UI文件,我们可以右键编辑修改