Python3.6特征目录和文件类仅限于用户文件夹

时间:2018-07-05 12:16:40

标签: python python-2.7 python-3.6 traits file-browser

我有以下代码根据python特性创建文件和目录对象。使用python 2.7,一切都很好,但是当我切换到python 3.6时,文件浏览器仅限于users文件夹。

Python 3.6: only users folder

Python 2.7:enter image description here

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

0 个答案:

没有答案