代码错误:TypeError:预期的str,字节或os.PathLike对象,而不是_io.TextIOWrapper

时间:2020-02-13 10:52:28

标签: python python-3.x user-interface tkinter typeerror

我正在尝试保存.txt,但是会出现此错误:TypeError: expected str, bytes or os.PathLike object, not _io.TextIOWrapper

代码如下:

def saveas():
    window.filename =  filedialog.asksaveasfile(initialdir = "/",title = "Select file",filetypes = (("text files","*.txt"),("all files","*.*")))
    file=open(window.filename, 'w')
    file.writelines(escritura.get('1.0', END))
    file.close()
    print(escritura.get('1.0', END))

如果您知道,请帮助我

2 个答案:

答案 0 :(得分:1)

使用startTime := time.Now() // startTime will be in UTC and the timezone // will be set to whatever your local timezone is // load the location you want to display the time in loc, _ := time.LoadLocation("Europe/Berlin") // set timezone and display: timeToDisplay := startTime.In(loc).String() fmt.Println(timeToDisplay) 属性访问文件-> .name

例如:

window.filename.name

答案 1 :(得分:0)

escritura.get('1.0', END)可能已经打开了,所以也许您应该执行escritura.get('1.0', END).read(),因为我还不能发表评论,所以您可以type(escritura.get('1.0', END))