1

tkFileDialog.askdirectory()如果目录包含非 ASCII 字符,我在 Windows 上遇到问题。

这是一个例子:

import tkFileDialog
# Open folder C:\notused\weekly\1\Music\岩崎 琢
# (But while the dialog is open, the dialog itself shows the name mangled
# as "C:\notused\weekly\1\Music\?? ?")
o_result = tkFileDialog.askdirectory()
# Return result is unicode, which is correct..
print type(o_result)
# ...but the result string has the non-English characters mangled.
print o_result
# And it's not just the display, they seem to be actually mangled.
print ord(o_result[-1])
# The ordinal value of the final character is the same as the question-mark
print ord('?')

我注意到对话框本身在我触摸它之前就显示了损坏的字符串(这告诉我这不是我的处理错误),但我找不到任何其他参数或设置可以更改以使其askdirectory()在这种情况下正常工作.

我错过了什么?

4

1 回答 1

0

我在 Windows 下使用了 tkFileDialog,终于解决了我的文件名解析问题:

import Tkinter
Tkinter.wantobjects = 0

请注意,我正在使用askopenfiles()而不是askdirectory(),但它可能适用于您的情况。

于 2013-07-17T00:32:44.390 回答