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

步骤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. 厉害了!不重启JVM,替换掉已经加载的类
  2. 最新JAVA性能调优实战教程_java性能调优实战 - osc_9z8xc00s的个人空间 - OSCHINA - 中文开源技术交流社区...
  3. .net安装部署中添加卸载程序简单方法
  4. FFmpeg学习1:视频解码
  5. Sequelize 中文文档 v4 - Querying - 查询
  6. 中石油训练赛 - Flow Finder(树上模拟)
  7. Git 克隆远程项目到本地_01
  8. Atitit.atiInputMethod v2词库清理策略工具    q229
  9. eclipse 3.x中热部署WEB程序TOMCAT配置
  10. [渝粤教育] 重庆工程职业技术学院 数控机床编程与操作 参考 资料
  11. Java生态技术体系科普
  12. 《数据结构》— 数据结构图文解析系列
  13. latex表格内容上下居中_Latex-表格内容垂直居中
  14. 北斗三号频点_海格通信发布国内首批北斗三号双模应用专用芯片
  15. Win11勒索软件防护怎么打开?Win11安全中心勒索软件防护如何设置
  16. Unity3d Android SDK接入解析(四)通用的Android SDK接入中间件
  17. 蓝牙鼠标windows linux,Windows+Linux+MacOS三大系统共用蓝牙鼠标
  18. [转载]荷香如歌_xing2516_新浪博客
  19. linux常见问题解答
  20. 2017年6月大学英语六级真题(第一套)阅读理解(一)(每日一摸)

热门文章

  1. GitHub 登录失败
  2. 服务器和客户端连接不稳定,服务器和客户端的连接方法
  3. 2020.05.20软件构造听课笔记
  4. 计算机毕业设计 汉语多音字注音研究
  5. Linux中的竖线(|)意义——管道符号的简单介绍
  6. springboot2.0 多线程并发执行任务
  7. VS 和Visual Assist X快捷键
  8. 搭建FitNesse框架
  9. linux脚本加密 upx,#加解密#LinuxShell加密解密方法(shc/gzexe/UPX)
  10. parrallel for matlab,[转载]MATLAB并行计算工具箱 -- Paralleln