1

我正在尝试使用 Tkinter 和 python 2.7 编写我的第一个程序。我安装的Tkinter库是:ActiveTcl8.5.14。我的问题是:这种组合有什么好的在线资源?我一直在通过反复试验取得进展,但现在我被困住了。我正在尝试将 stringVar 设置为文件名。但我担心我使用的是错误版本的 Python 或 Tkinter 的代码。

def abrir_capitulo():
    ##Dialog box for selecting the chapter to be loaded.
    import tkFileDialog
    WORDLIST_FILENAME = tkFileDialog.askopenfilename(mode='r',parent=master,title="Archivo para abrir")

这是回溯:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1470, in __call__
    return self.func(*args)
  File "/Users/Noel/Documents/Professional Development/MIT CS 6.0/Recall Game/Recall_Game.py", line 103, in abrir_capitulo
    WORDLIST_FILENAME = tkFileDialog.askopenfilename(mode='r',parent=master,title="Archivo para abrir")
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/tkFileDialog.py", line 125, in askopenfilename
    return Open(**options).show()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/tkCommonDialog.py", line 48, in show
    s = w.tk.call(self.command, *w._options(self.options))
TclError: bad option "-mode": must be -defaultextension, -filetypes, -initialdir, -initialfile, -message, -multiple, -parent, -title, -typevariable, or -command
4

1 回答 1

0

根据askopenfilename 文档,askopenfilename 没有mode参数。

WORDLIST_FILENAME = tkFileDialog.askopenfilename(parent=master,title="Archivo para abrir")

有关文档,请参阅http://wiki.python.org/moin/TkInter

于 2013-08-18T06:02:10.460 回答