我有以下代码根据python特性创建文件和目录对象。使用python 2.7,一切都很好,但是当我切换到python 3.6时,文件浏览器仅限于users文件夹。
import os
from traits.api import (HasTraits, File, Directory)
from traitsui.api import (View, UItem, HGroup)
os.chdir('C:/')
class TestTraitsFile(HasTraits):
file = File(value='C:/')
direc = Directory(value='C:/')
def traits_view(self):
view = View(
HGroup(
UItem('file', style='custom'),
UItem('direc', style='custom'),
),
resizable=True,
)
return view
if __name__ == '__main__':
obj = TestTraitsFile()
print("obj.file = ", obj.file) # 'obj.file = ', 'C:/'
print("obj.direc = ", obj.direc) # 'obj.direc = ', 'C:/'
obj.configure_traits()
print("obj.file = ", obj.file) # 'obj.file = ', 'C:/'
print("obj.direc = ", obj.direc) # 'obj.direc = ', 'C:/'
有人知道解决此问题的方法吗?
最好, SJF