Save File Dialog in Tkinter

前端 未结 1 1614
日久生厌
日久生厌 2020-12-15 06:52

I am implementing a GUI based text editor in python.
I have displayed the text area but when I try to use the asksaveasfile method in Tkinter, it shows that the file has

相关标签:
1条回答
  • 2020-12-15 07:36

    The function name is asksaveasfilename. And it should be qualified as tkFileDialog.asksaveasfilename. And it does not accept mode argument.

    Maybe you want to use tkFileDialog.asksaveasfile.

    def file_save():
        f = tkFileDialog.asksaveasfile(mode='w', defaultextension=".txt")
        if f is None: # asksaveasfile return `None` if dialog closed with "cancel".
            return
        text2save = str(text.get(1.0, END)) # starts from `1.0`, not `0.0`
        f.write(text2save)
        f.close() # `()` was missing.
    
    0 讨论(0)
提交回复
热议问题