可能将文本保存在Tkinter Python 3程序的文本框中保存到文本文件中

时间:2017-09-09 21:46:56

标签: python python-3.x tkinter textbox

这是我的代码删除了一些位,这会将输出发送到" Notes.txt"文本文件,但它通常只发送一个小数点后跟随机的十进制数字。希望是初学者的错误。下面的代码片段:

class Window (Frame):
    def __init__(self, master = None):
        Frame.__init__(self, master)
        self.master = master
        self.init_window()

    def init_window (self):#This sets up the 'Window Frame'
        self.master.title("'Joe Banks' - Witty name to follow")
        self.pack(fill=BOTH, expand=1)
        #Irrelevant File Menus and buttons removed
        #Adds Textbox for typing Notes etc.
        blankTextbox = Text(app, width = 30, height=4, font=("CenturyGothic",18))
        blankTextbox.place(x=270, y=550, anchor="c")

然后以不同的程序:

def saveTextboxToFile(self):
    fileContent = str(Text(app, width = 30, height=4, font=("CenturyGothic",18)))
    file = open("Notes.txt", "w")
    file.write(fileContent)
    file.close()

0 个答案:

没有答案