本文要实现的是在按下两个按钮,分别打印两句话

步骤1:先通过Extension Wizard建立出scripted模块

将模块的名字命名为Test

步骤2:找到名为Test.py的文件
将里面的代码修改成下面这样

import logging
import osimport vtkimport slicer
from slicer.ScriptedLoadableModule import *
from slicer.util import VTKObservationMixinclass Test(ScriptedLoadableModule):"""Uses ScriptedLoadableModule base class, available at:https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py"""def __init__(self, parent):ScriptedLoadableModule.__init__(self, parent)self.parent.title = "Test"  # TODO: make this more human readable by adding spacesself.parent.categories = ["Examples"]  # TODO: set categories (folders where the module shows up in the module selector)self.parent.dependencies = []  # TODO: add here list of module names that this module requiresself.parent.contributors = ["John Doe (AnyWare Corp.)"]  # TODO: replace with "Firstname Lastname (Organization)"# TODO: update with short description of the module and a link to online module documentationself.parent.helpText = """
This is an example of scripted loadable module bundled in an extension.
See more information in <a href="https://github.com/organization/projectname#Test">module documentation</a>.
"""# TODO: replace with organization, grant and thanksself.parent.acknowledgementText = """
This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc., Andras Lasso, PerkLab,
and Steve Pieper, Isomics, Inc. and was partially funded by NIH grant 3P41RR013218-12S1.
"""class TestWidget(ScriptedLoadableModuleWidget, VTKObservationMixin):"""Uses ScriptedLoadableModuleWidget base class, available at:https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py"""def __init__(self, parent=None):"""Called when the user opens the module the first time and the widget is initialized."""ScriptedLoadableModuleWidget.__init__(self, parent)VTKObservationMixin.__init__(self)  # needed for parameter node observationself.logic = Noneself._parameterNode = Noneself._updatingGUIFromParameterNode = Falsedef setup(self):"""Called when the user opens the module the first time and the widget is initialized."""ScriptedLoadableModuleWidget.setup(self)

可以看到此时的界面中什么也没有

步骤3:往代码中添加按钮的代码

import logging
import osimport vtkimport slicer
from slicer.ScriptedLoadableModule import *
from slicer.util import VTKObservationMixinclass Test(ScriptedLoadableModule):"""Uses ScriptedLoadableModule base class, available at:https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py"""def __init__(self, parent):ScriptedLoadableModule.__init__(self, parent)self.parent.title = "Test"  # TODO: make this more human readable by adding spacesself.parent.categories = ["Examples"]  # TODO: set categories (folders where the module shows up in the module selector)self.parent.dependencies = []  # TODO: add here list of module names that this module requiresself.parent.contributors = ["John Doe (AnyWare Corp.)"]  # TODO: replace with "Firstname Lastname (Organization)"# TODO: update with short description of the module and a link to online module documentationself.parent.helpText = """
This is an example of scripted loadable module bundled in an extension.
See more information in <a href="https://github.com/organization/projectname#Test">module documentation</a>.
"""# TODO: replace with organization, grant and thanksself.parent.acknowledgementText = """
This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc., Andras Lasso, PerkLab,
and Steve Pieper, Isomics, Inc. and was partially funded by NIH grant 3P41RR013218-12S1.
"""class TestWidget(ScriptedLoadableModuleWidget, VTKObservationMixin):"""Uses ScriptedLoadableModuleWidget base class, available at:https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py"""def __init__(self, parent=None):"""Called when the user opens the module the first time and the widget is initialized."""ScriptedLoadableModuleWidget.__init__(self, parent)VTKObservationMixin.__init__(self)  # needed for parameter node observationself.logic = Noneself._parameterNode = Noneself._updatingGUIFromParameterNode = Falsedef setup(self):"""Called when the user opens the module the first time and the widget is initialized."""ScriptedLoadableModuleWidget.setup(self)import qt#设添加两个按钮self.button_1 = qt.QPushButton("button1")self.button_1.enabled = Trueself.button_2 = qt.QPushButton("button2")self.button_2.enabled = True#添加到界面中self.layout.addWidget(self.button_1)self.layout.addWidget(self.button_2)#信号和槽函数self.button_1.connect('clicked(bool)', self.button_1_clicked)self.button_2.connect('clicked(bool)', self.button_2_clicked)#垂直布局self.layout.addStretch(1)def button_1_clicked(self):print("button1 clicked===>")def button_2_clicked(self):print("button2 clicked===>")

可以看到界面最终变成了下图这样

点击两个按钮,将会进行打印

在slicer中编写scripted模块相关推荐

  1. Slicer学习笔记(三十九)slicer中Markups模块

    Slicer学习笔记(三十九)slicer中Markups模块 1.概念 1.1.Markups模块简介 1.2.应用方向 1.3.界面面板 1.Markups List 2.Buttons And ...

  2. Magento中如何在模块中使用多张数据表并配置多个model?

    功能介绍: 引用magento开发人员的一句话: Magento has basic one resource to one table resource. 也即是一个资源对应一张数据表. 当有时候, ...

  3. python io模块_python中的StringIO模块

    原博文 2015-10-23 15:21 − # python中的StringIO模块 标签:python StringIO --- > 此模块主要用于在内存缓冲区中读写数据.模块是用类编写的, ...

  4. 如何编写Python模块/包?

    本文翻译自:How to write a Python module/package? I've been making Python scripts for simple tasks at work ...

  5. [转]使用 C 编写 Lua 模块

    Lua 作为一种小巧的语言,一般都是嵌入到 C/C++ 中作为扩展语言,但是也可以作为独立的脚本语言使用,并且可以使用 C/C++ 编写扩展模块.在参考资料 [1] 中有怎样用 C/C++ 编写模块的 ...

  6. python中模块和函数_Python中函数和模块的体验与使用

    函数基础 目标 函数的快速体验 函数的基本使用 函数的参数 函数的返回值 函数的嵌套调用 在模块中定义函数 01. 函数的快速体验 1.1 快速体验 所谓函数,就是把 具有独立功能的代码块 组织为一个 ...

  7. windows编写linux脚本,Windows PowerShell:共享您的脚本 - 在脚本中编写 Cmdlet | Microsoft Docs...

    Windows PowerShell:在脚本中编写 Cmdlet 08/17/2016 本文内容 Don Jones Windows PowerShell v2 中一项很酷的新功能是能够编写性能明显改 ...

  8. python 利用pyinstaller 编译.exe文件过程中编写完的.exe文件执行过程中闪退

    问题描述: python 利用pyinstaller 编译.exe文件过程中编写完的.exe文件执行过程中闪退,并提示no module named 'pyproj.datadir' 解决方法: 闪退 ...

  9. WebService大讲堂之Axis2(9):编写Axis2模块(Module)

    Axis2可以通过模块(Module)进行扩展.Axis2模块至少需要有两个类,这两个类分别实现了Module和Handler接口.开发和使用一个Axis2模块的步骤如下: 1. 编写实现Module ...

最新文章

  1. Oracle数据库备份与恢复1\Oracle数据库备份与恢复(1)exp和imp 之三
  2. 50+篇《神经架构搜索NAS》2020论文合集
  3. linux svn安装
  4. array,arraylist,string的总结
  5. python-字符串·文件·集合操作
  6. 读书笔记《集体智慧编程》Chapter 2 : Make Recommendations
  7. mysql连接非常慢的觖决办法及其它常见问题解决办法
  8. Mybatis面试题-日更
  9. 短视频矩阵系统,抖音矩阵系统,抖音获客系统源码。look
  10. 2021 年人工智能全球最具影响力学者榜单 AI 2000 发布
  11. 公共关系与人际交往能力
  12. python手把手教你创作趣味词云(保姆级贴心)
  13. 华硕装鸿蒙系统,智能家居 篇八:解决华硕路由器设置不当造成传感器延迟
  14. Linux中实现定时任务详解
  15. TxtView 手机文本阅读器
  16. 如何根据vin码查询_vin查配置 车辆VIN码查询车辆基本配置信息 知道车辆vin码怎么查配置...
  17. CTF SSTI模板注入详解
  18. Inno Setup汉化方法
  19. Nvidia显卡驱动与Cuda关系,Cuda的driver API 和runtime API
  20. table表格中实现圆角效果

热门文章

  1. php游戏简单模块,PHP编写的25个游戏脚本
  2. platform总线
  3. 跑腿app开发软件需要具体哪些功能
  4. NXP JN5169使用代码模板新建外设工程
  5. 微信支付上线遇到的nss问题 (openjdk引起的祸)
  6. 共享超级蜘蛛池,使用经验和技巧。
  7. Mission Planner中级应用(APM或PIX飞控)1——振动测量
  8. Mission Planner初学者安装调试教程指南(APM或PIX飞控)2——安装与更新
  9. vue+openlayers实现行政边界、标注交互、效果弹窗
  10. 基于zynq的千兆网udp项目_基于FPGA的千兆网UDP通信分析