_tkinter.TclError:无法打开" optionDB .txt":没有这样的文件或目录

时间:2017-06-25 16:44:23

标签: tkinter

我正在尝试打开包含tkinter样式选项的外部文件,但由于某种原因,它说该文件无法找到。

以下是完整的追溯:

Traceback (most recent call last):
  File "C:/Users/stjur/Desktop/STYLING.py", line 5, in <module>
    root.option_readfile('optionDB .txt')
  File "C:\Users\stjur\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 871, in option_readfile
    self.tk.call('option', 'readfile', fileName, priority)
_tkinter.TclError: couldn't open "optionDB .txt": no such file or directory

我的代码行:

from tkinter import *
root = Tk()
root.configure(background="#4d4d4d")#TOP LEVEL STYLING
root.option_readfile('optionDB .txt')

mytext=Text(root,background='#101010',foreground='#D6D6D6',borderwidth=18,relief='sunken',width=17,height=5)

我试着在不同的地方研究答案,但我找不到,有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:0)

我认为这一行是问题所在:

root.option_readfile('optionDB .txt')

我怀疑您尝试加载的文件名称为optionDB.txt,但您的代码中存在拼写错误:optionDB .txt(请注意文件扩展名前的空格)

除此之外,请确保您的脚本与您尝试加载的文本文件位于同一位置;如果没有,那就给它完整的路径。