PyQt5练手若干事项

第一部分:编程环境搭配

1. Anaconda3-4.2.0-Windows-x86.exe,(先安装这个,在c:\Anaconda3)

2. PyQt5-5.6-gpl-Py3.5-Qt5.6.0-x32-2.exe,(再安装这个,会自动在找到目录c:\Anaconda3,使用"import PyQt5"验证一下是否安装成功了)

3. eric6-17.08,(打开命令行,切换到install.py所在路径,输入:python install.py,进行安装。安装完成后需要配置API,然后启用自动补全)

第二部分:软件打包

1. .qrc文件、.ui文件转换成.py

pyuic5 xxx.ui –o xxx.py
2. 打包工具:pyinstaller : pip install pyinstaller (打包成exe)
pyinstaller -F -w xxxxxx.py  xxxxx.py  ...  xxxxxx.py


第三部分:使用vtk

#!/usr/bin/env python
# Contributed by Eric E Monson
 
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import QApplication
import vtk
from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
import sys
 
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(603, 553)
        self.centralWidget = QtGui.QWidget(MainWindow)
        self.gridlayout = QtGui.QGridLayout(self.centralWidget)
        self.vtkWidget = QVTKRenderWindowInteractor(self.centralWidget)
        self.gridlayout.addWidget(self.vtkWidget, 0, 0, 1, 1)
        MainWindow.setCentralWidget(self.centralWidget)
 
class SimpleView(QtGui.QMainWindow):
 
    def __init__(self, parent = None):
        QtGui.QMainWindow.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ren = vtk.vtkRenderer()
        self.ui.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
        self.iren = self.ui.vtkWidget.GetRenderWindow().GetInteractor()
 
        # Create source
        source = vtk.vtkSphereSource()
        source.SetCenter(0, 0, 0)
        source.SetRadius(5.0)
 
        # Create a mapper
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(source.GetOutputPort())
 
        # Create an actor
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
 
        self.ren.AddActor(actor)
 
if __name__ == "__main__":
 
    app = QApplication(sys.argv)
    window = SimpleView()
    window.show()
    window.iren.Initialize() # Need this line to actually show the render inside Qt
    sys.exit(app.exec_())


都是网上搬来的内容,都不算原创,忙里偷闲,等有需求的时候再继续,先就这样吧。

参考文献:

  1. https://zhuanlan.zhihu.com/p/28085650
  2. https://sourceforge.net/projects/pywin32/files/
  3. https://blog.csdn.net/wangle_08/article/details/79235719
  4. https://blog.csdn.net/mccoy39082/article/details/80472730
  5. http://www.vtk.org/Wiki/VTK/Examples/Python/Widgets/EmbedPyQt2
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值