How to 'save as' an edited image (png) using a file dialog in tkinter and Pil in Python
I finally figured it out. I ended up creating each component (the image and text) separately and then saving the final image as a composite.Here is the final code:
def onOpen(self): im = Image.open(askopenfilename()) caption = simpledialog.askstring("Label", "What would you like the label on your picture to say?") fontsize = 30 if im.mode != "RGBA": im = im.convert("RGBA") txt = Image.new('RGBA', im.size, (255,255,255,0)) draw = ImageDraw.Draw(txt) font = ImageFont.truetype("arial.ttf", fontsize) draw.text((0, 0),caption,(255,0,0),font=font) file = filedialog.asksaveasfile(mode='w', defaultextension=".png", filetypes=(("PNG file", "*.png"),("All Files", "*.*") )) if file: abs_path = os.path.abspath(file.name) out = Image.alpha_composite(im, txt) out.save(abs_path) # saves the image to the input file name.