Vscode开发基于PYQT的Python界面程序

1,239 阅读1分钟

持续创作,加速成长!这是我参与「掘金日新计划 · 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中右键项目,新建一个界面配置 在这里插入图片描述

  • 创建新窗体 在这里插入图片描述

  • 创建完成

image.png

  • 我们可以拖拽各种需要的控件,进行页面布局

image.png

  • 点击保存,会生成一个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的文件,用于编写按钮,文本的的控制和处理代码

image.png

  • 对于已经写好的UI文件,我们可以右键编辑修改

image.png