Python3.8.8 运行文件提示Cannot open console output buffer for reading

解释器是Anaconda Python 3.8.8,运行程序到打开文件这一步就报错Cannot open console output buffer for reading。不知道咋整,程序就卡在这里了
看一下代码:

if file1 == True:
    doc1 = simpledialog.askstring('文件','请输入文件目录')#输入目录
    doc2 = messagebox.askyesno('文件','您是否要编辑此文档?')#打开前询问用户是否编辑
    if doc2 == True: 
        f = open(file1,"a")
        txt = f.read and write
        print(txt)
    else:
        f = open(file1)
        txt = f.read
        print(txt)  

第二行输入目录以后用Open函数,然后运行到第五行就报错
然后这个文件我导入了Tkinter库,第11行和第7行可以换成messagebox.showinfo吗?然后看看第六行有什么错误吗?
咋整?特别急!