问题描述
我一直在尝试找到一种方法来保存我一直在使用的文本编辑器应用程序中Tkinter文本框中的格式。
def bold():
boldFont = font.Font(textBox,textBox.cget("font"))
boldFont.configure(weight = "bold")
textBox.tag_configure("bold",font = boldFont)
currentTags = textBox.tag_names("sel.first")
if ("bold" in currentTags):
textBox.tag_remove("bold","sel.first","sel.last")
else:
textBox.tag_add("bold","sel.last")
boldButton = Button(toolbarFrame,text = "B",command = bold,font = ('Times New Roman',11,'bold'))
当我选择文本并按下按钮时,该按钮在文本框中起作用,但是当我保存文件时,格式会被删除。我将其保存到.doc文件。
def saveNote():
name = str(nameBox.dump('1.0',END))
f = open(name + ".doc","w")
text = str(textBox.dump('1.0',"a")
f.write(text)
f.close()
我尝试同时使用get()
函数和dump()
函数,但都没有起作用。
保存文件时如何保持格式?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)