def translate_text(): text = input_text.get("1.0", "end-1c") translation = "" words = text.split() for word in words: if word in dictionary: translation += dictionary[word] + " " else: translation += word + " " output_text.delete("1.0", tk.END) output_text.insert(tk.END, translation)
save_button = tk.Button(root, text="Lưu thành PDF", command=save_as_pdf) save_button.pack()
output_text = tk.Text(root) output_text.pack()
root = tk.Tk()
def create_pdf(text, filename): writer = PdfWriter() reader = PdfReader('example.pdf') # Template PDF writer.add_page(reader.pages[0])
def save_as_pdf(): text = output_text.get("1.0", "end-1c") create_pdf(text, "output.pdf") messagebox.showinfo("Thành công", "Đã lưu thành file PDF")