当前位置: 首页 > news >正文

PySide6+VSCode Python可视化环境搭建

pip install pyside6

下载本期源码
vscode装一个PYQT Integration插件,设置好两个路径(下面有个脚本用于获取路径)

用everything的童鞋注意了:工具/选项/索引/强制重建

重启vscode可以看到,右击.ui文件时出现可以操作的菜单

我们New一个Form默认生成一个.ui文件,然后点击编译,就会出现我们需要的Ui_untitled.py,这就是编译出来的文件。在test.py中输入以下代码F5运行,对话框就出现了


import sys
from Ui_untitled import Ui_Dialog
from PySide6.QtWidgets import QApplication, QDialog  # 假设您使用的是 PyQt5class MyDialog(QDialog):def __init__(self):super(MyDialog, self).__init__()self.ui = Ui_Dialog()  # 假设 Ui_Dialog 是您的 UI 文件生成的类self.ui.setupUi(self)  # 将当前对话框实例传递给 setupUi 方法if __name__ == "__main__":app = QApplication([])win = MyDialog()win.show()app.exec_()

最后附上一段获取exe文件路径的脚本,方便路径的复制粘贴:(注意不要重复运行,里面有添加环境变量操作,重复运行会添加重复的环境变量)

import os
import sys
import subprocess
from pathlib import Path
from win32com.client import Dispatch    #要安装依赖:python -m pip install pypiwin32# 1. 搜索Python目录并设置pkgDir变量
def find_python_directory():for root, dirs, files in os.walk('C:/Users/Administrator/AppData/Local/Programs'):if 'python.exe' in files:return Path(root)return Nonepython_dir = find_python_directory()
if python_dir is None:print("Python not found.")sys.exit(1)pkg_dir = python_dir / 'Lib' / 'site-packages'
print(f"Found Python at: {python_dir}")
print(f"Package directory: {pkg_dir}")# 2. 在pkgDir中搜索Designer.exe并创建桌面快捷方式
def create_shortcut(target, shortcut_path, name):shell = Dispatch('WScript.Shell')shortcut = shell.CreateShortCut(str(shortcut_path))shortcut.Targetpath = targetshortcut.WorkingDirectory = str(Path(target).parent)shortcut.save()desktop_path = Path.home() / 'Desktop'
designer_exe = None
for file in pkg_dir.rglob('Designer.exe'):designer_exe = filebreakif designer_exe:shortcut_name = 'Designer.lnk'create_shortcut(str(designer_exe), desktop_path / shortcut_name, 'Designer')print(f"Shortcut created for Designer.exe on the desktop.")
else:print("Designer.exe not found.")# 3. 在pkgDir中搜索pyuic6.exe并添加到系统环境变量
pyside6_uic_exe_path = None
for file in python_dir.rglob('pyside6-uic.exe'):pyside6_uic_exe_path = file.parentbreak
if pyside6_uic_exe_path:current_path = os.environ['PATH']new_path = f"{current_path};{str(pyside6_uic_exe_path)}"subprocess.run(['setx', 'PATH', new_path, '/M'], check=True)print(f"pyside6-uic.exe directory added to system PATH.")
else:print("pyside6-uic.exe not found.")pyside6_uic_exe = str(pyside6_uic_exe_path) + '\\pyside6-uic.exe'
print('-----------------------------------------------------------------------------')
print(pyside6_uic_exe)
print(designer_exe)
print('-----------------------------------------------------------------------------')

http://www.lryc.cn/news/311343.html

相关文章:

  • 【设计】设计一个web版的数据库管理平台后端精要
  • 没有硬件基础可以学单片机吗?
  • ChatGPT引领的AI面试攻略系列:cuda和tensorRT
  • 【战略前沿】人形机器人制造商Figure获得了OpenAI、Jeff Bezos、Nvidia和其他科技巨头的资助
  • 多块磁盘组磁盘离线导致VSAN存储崩溃的VSAN数据恢复案例
  • Jenkins 的安装(详细教程)
  • 使用html网页播放多个视频的几种方法
  • python 基础知识点(蓝桥杯python科目个人复习计划58)
  • 【基于React实现共享单车管理系统】—React基础知识巩固(二)
  • 云桥通+跨境电商:SDWAN企业组网优化跨境网络案例
  • 服务器有几种http强制跳转https设置方法
  • web坦克大战小游戏
  • 如何使用生成式人工智能探索视频博客的魅力?
  • gpt批量工具,gpt批量生成文章工具
  • Python知识汇总
  • WEB面试题
  • Android Studio 六大基本布局详解
  • 如何应对IT服务交付中的问题?
  • [Python] 缓存实用工具
  • php反序列化字符逃逸
  • 延迟加载(Lazy Initialization)的单例模式
  • C++三级专项 流感传染
  • 如何用Elementor创建WordPress会员网站
  • 【脑切片图像分割】MATLAB 图像处理 源码
  • 深度学习系列61:在CPU上运行大模型
  • IO接口 2月5日学习笔记
  • Android Studio开发(一) 构建项目
  • stm32flash模拟eeprom
  • 多模态MLLM都是怎么实现的(2)-DDPM
  • QT----写完的程序打包为APK在自己的手机上运行