PCM_Report/test_pyside6.py

81 lines
2.0 KiB
Python
Raw Normal View History

2025-12-11 14:32:31 +08:00
#!/usr/bin/env python3
"""
测试PySide6是否正常工作
"""
import sys
def test_pyside6_import():
"""测试PySide6导入"""
print("测试PySide6导入...")
try:
from PySide6.QtCore import QCoreApplication
print("✅ PySide6.QtCore 导入成功")
except ImportError as e:
print(f"❌ PySide6.QtCore 导入失败: {e}")
return False
try:
from PySide6.QtGui import QGuiApplication
print("✅ PySide6.QtGui 导入成功")
except ImportError as e:
print(f"❌ PySide6.QtGui 导入失败: {e}")
return False
try:
from PySide6.QtWidgets import QApplication, QWidget
print("✅ PySide6.QtWidgets 导入成功")
except ImportError as e:
print(f"❌ PySide6.QtWidgets 导入失败: {e}")
return False
return True
def test_simple_app():
"""测试简单的Qt应用程序"""
print("\n测试简单Qt应用程序...")
try:
from PySide6.QtWidgets import QApplication, QLabel
app = QApplication(sys.argv)
# 创建一个简单的标签
label = QLabel("PySide6 测试成功!")
label.show()
print("✅ Qt应用程序创建成功")
print("关闭窗口来继续...")
# 运行应用程序
app.exec()
return True
except Exception as e:
print(f"❌ Qt应用程序创建失败: {e}")
return False
def main():
print("PySide6 测试工具")
print("=" * 40)
# 1. 测试导入
if not test_pyside6_import():
print("\n❌ PySide6导入测试失败")
return
print("\n✅ 所有PySide6模块导入成功")
# 2. 询问是否测试GUI
choice = input("\n是否测试GUI应用程序? (y/n): ").strip().lower()
if choice in ['y', 'yes', '']:
test_simple_app()
print("\n测试完成!")
if __name__ == "__main__":
main()