科学计算三维可视化---Traits介绍

简介

Traits是开源扩展库,Traits本身与科学计算可视化没有直接关联,但他其实TVTK,Mayavi,TraitsUI基础

安装:

pip3 install traits-4.6.0-cp36-cp36m-win_amd64.whl
pip3 install traits
from traits.api import HasTraits    进行测试

使用:

traits属性可以像类的属性来定义,但是要像实例的属性来使用
>>> from traits.api import HasTraits
>>> from traits.api import HasTraits,Color
>>>
>>> class Circle(HasTraits):
...     color = Color  #traits属性可以像类的属性来定义,但是要像实例的属性来使用
...
>>> c = Circle()
>>> Circle.color    #不是类的属性
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'Circle' has no attribute 'color'
>>> c.color       #是实例的属性
<PyQt4.QtGui.QColor object at 0x000000000AAA74A8>
>>> c.color = 'red'
>>> c.color.getRgb()
(255, 0, 0, 255)
>>> c.color = 'abc'  #按照严格的类型来区别变量,并且会给出明确的错误信息和使用提示
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-p
ackages\traits\trait_handlers.py", line 173, in error
    value )
traits.trait_errors.TraitError: The 'color' trait of a Circle instance must be a
 string of the form (r,g,b) or (r,g,b,a) where r, g, b, and a are integers from
0 to 255, a QColor instance, a Qt.GlobalColor, an integer which in hex is of the
 form 0xRRGGBB, a string of the form #RGB, #RRGGBB, #RRRGGGBBB or #RRRRGGGGBBBB
or 'aliceblue' or 'antiquewhite' or 'aqua' or 'aquamarine' or 'azure' or 'beige'
 or 'bisque' or 'black' or 'blanchedalmond' or 'blue' or 'blueviolet' or 'brown'
.............

 

 

>>> c.configure_traits()  #出现配置属性框,供我们选择颜色

>>> c.configure_traits()
True  #选择颜色后返回True
>>> c.color
<PyQt4.QtGui.QColor object at 0x000000000EA74D68>  #现在返回的颜色与我们选择的一致

 

转载于:https://www.cnblogs.com/ssyfj/p/9308013.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值