嗨,我是GUI编程新手,所以在尝试了PyQt一小段时间后,我发现了Enaml,这使得生产更加容易。在
我正在尝试一个小部件,它可以改变日期时间。日期时间对象或日期时间.time对象,但结果它们是只读的。那我怎么能做到呢?或者需要一个setter来改变属性,或者我可以写一个变量?在
我的最低工作解决方案是:
from __future__ import print_function
import datetime
import os
from atom.api import Atom, Unicode, Range, Typed, observe, Value, Bool
class SimulationCase(Atom):
startDateTime = datetime.datetime.strptime('05.03.2015-5','%d.%m.%Y-%H')
currentDateTime = startDateTime
endDateTime = startDateTime+ datetime.timedelta(days=int(5))
incrementTime = datetime.time(1,0,0)
def main():
case = SimulationCase()
print(case.currentDateTime)
a = datetime.time(1,0,0)
print(a)
#This is where the problem occures, comment out the line under for a working solution.
case.incrementTime = a
if __name__ == '__main__':
main()
你的解决方案不正确。使用成员类型在Atom类中创建成员,然后可以通过普通的
__getattr__
机制访问和设置这些成员。在示例代码的正确示例:
我找到了一个基于属性.py原子核开发团队的文件。 设置程序可以通过添加一个带有集变量(self,variable)和\u get_variable(self):的函数来完成 因此,一个可能的解决方案是:
相关问题 更多 >
编程相关推荐