当我在python中将其另存为pdf时,请将其';显示错误

当我在python中将其另存为pdf时,请将其';显示错误,python,tkinter,Python,Tkinter,我想将文档另存为pdf,但当我将其另存为pdf时,其保存成功,但在尝试打开pdf文件时显示错误 def save_file(event = None): global text_url try: if text_url: content = str(text_editor.get(1.0,tk.END)) with open(text_url,"w",encoding=&quo

我想将文档另存为pdf,但当我将其另存为pdf时,其保存成功,但在尝试打开pdf文件时显示错误

def save_file(event = None):
       global text_url
       try:
          if text_url:
             content = str(text_editor.get(1.0,tk.END))
             with open(text_url,"w",encoding="utf-8") as for_read:
                for_read.write(content)
          else:
             text_url=filedialog.asksaveasfile(mode = "w",defaultextension="txt",filetypes=(("Text file","*.txt"),("All files","*.*"),("PDF","*.pdf")))
             conrent2 = text_editor.get(1.0,tk.END)
             text_url.write(content2)
             text_url.close()
       except:
             return

怎么了?这是一个有效的pdf文件吗?说
,例外情况除外,例如e:print(e)
,并用它更新Q,或者如果是其他错误,请详细说明。我认为你不能像这样创建一个pdf文件,你必须使用一些python pdf集成库来写入pdf文件。请花时间阅读并更新你的问题:将文本写入扩展名为.pdf的文件并不意味着它是一个pdf文件-它只是一个名称不正确的文本文件。