我的tkinker脚本不工作,它说错误“tuple”对象没有属性“read”,我如何解决这个问题?
我的代码在这里:https://pastebin.com/kLnmutcg
我的理论是为什么它说这个错误在这个代码中:
def save():
filename = filedialog.askopenfilename(filetypes=(("txt files","*.txt"),("All files","*.*")))
file = open=(filename, "wt")
def open():
filename = filedialog.askopenfilename(filetypes=(("txt files","*.txt"),("All files","*.*")))
file = open=(filename, "rt")
read = file.read()
text_box.insert(tk.END, read)我在试着复制一个记事本。
发布于 2022-02-16 21:29:37
正确的语法是:
file = open(filename, "wt")通过使用file = open=(filename, "wt"),您可以创建两个变量:file和open,它们都包含元组(filename, "wt")
也不要使用open作为变量/函数名,这是python内置的。您可以在文档中找到一个列表。
https://stackoverflow.com/questions/71149469
复制相似问题