• PySide6+VSCode Python可视化环境搭建


    pip install pyside6

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

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

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

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

    1. import sys
    2. from Ui_untitled import Ui_Dialog
    3. from PySide6.QtWidgets import QApplication, QDialog # 假设您使用的是 PyQt5
    4. class MyDialog(QDialog):
    5. def __init__(self):
    6. super(MyDialog, self).__init__()
    7. self.ui = Ui_Dialog() # 假设 Ui_Dialog 是您的 UI 文件生成的类
    8. self.ui.setupUi(self) # 将当前对话框实例传递给 setupUi 方法
    9. if __name__ == "__main__":
    10. app = QApplication([])
    11. win = MyDialog()
    12. win.show()
    13. app.exec_()

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

    1. import os
    2. import sys
    3. import subprocess
    4. from pathlib import Path
    5. from win32com.client import Dispatch #要安装依赖:python -m pip install pypiwin32
    6. # 1. 搜索Python目录并设置pkgDir变量
    7. def find_python_directory():
    8. for root, dirs, files in os.walk('C:/Users/Administrator/AppData/Local/Programs'):
    9. if 'python.exe' in files:
    10. return Path(root)
    11. return None
    12. python_dir = find_python_directory()
    13. if python_dir is None:
    14. print("Python not found.")
    15. sys.exit(1)
    16. pkg_dir = python_dir / 'Lib' / 'site-packages'
    17. print(f"Found Python at: {python_dir}")
    18. print(f"Package directory: {pkg_dir}")
    19. # 2. 在pkgDir中搜索Designer.exe并创建桌面快捷方式
    20. def create_shortcut(target, shortcut_path, name):
    21. shell = Dispatch('WScript.Shell')
    22. shortcut = shell.CreateShortCut(str(shortcut_path))
    23. shortcut.Targetpath = target
    24. shortcut.WorkingDirectory = str(Path(target).parent)
    25. shortcut.save()
    26. desktop_path = Path.home() / 'Desktop'
    27. designer_exe = None
    28. for file in pkg_dir.rglob('Designer.exe'):
    29. designer_exe = file
    30. break
    31. if designer_exe:
    32. shortcut_name = 'Designer.lnk'
    33. create_shortcut(str(designer_exe), desktop_path / shortcut_name, 'Designer')
    34. print(f"Shortcut created for Designer.exe on the desktop.")
    35. else:
    36. print("Designer.exe not found.")
    37. # 3. 在pkgDir中搜索pyuic6.exe并添加到系统环境变量
    38. pyside6_uic_exe_path = None
    39. for file in python_dir.rglob('pyside6-uic.exe'):
    40. pyside6_uic_exe_path = file.parent
    41. break
    42. if pyside6_uic_exe_path:
    43. current_path = os.environ['PATH']
    44. new_path = f"{current_path};{str(pyside6_uic_exe_path)}"
    45. subprocess.run(['setx', 'PATH', new_path, '/M'], check=True)
    46. print(f"pyside6-uic.exe directory added to system PATH.")
    47. else:
    48. print("pyside6-uic.exe not found.")
    49. pyside6_uic_exe = str(pyside6_uic_exe_path) + '\\pyside6-uic.exe'
    50. print('-----------------------------------------------------------------------------')
    51. print(pyside6_uic_exe)
    52. print(designer_exe)
    53. print('-----------------------------------------------------------------------------')

  • 相关阅读:
    转行IC后端学习计划,先看看他们是怎么做到的
    Langchain Chain - RouterChain 根据输入相关性进行路由的路由链
    测试用例的书写方式以及测试模板大全
    【深度学习CPU(番外篇)——初识总线】
    Confluence OGNL注入漏洞复现(CVE-2022-26134)
    springCloud在pom中快速修改运行环境,让配置不再繁琐
    PCI_PIN_Security_Requirements_Testing -PCI认证-安全行业基础篇4
    javascript开发五指棋和围棋
    物联网AI MicroPython传感器学习 之 DRV8833电机驱动模块
    安卓系列机型 框架LSP 安装步骤 支持多机型 LSP框架通用安装步骤【二】
  • 原文地址:https://blog.csdn.net/yingang2009/article/details/136408480