Код: Выделить всё
def onOpen(self):
im = Image.open(askopenfilename())
caption = simpledialog.askstring("Label", "What would you like the label on your picture to say?")
fontsize = 15
if im.mode != "RGB":
im = im.convert("RGB")
draw = ImageDraw.Draw(im)
font = ImageFont.truetype("arial.ttf", fontsize)
draw.text((0, 0),str(caption),(255,0,0),font=font)
file = filedialog.asksaveasfile(mode='w', defaultextension=".png")
if file:
file.write(im)
file.close()
< /code>
Однако я получаю следующую ошибку при ее запуска: < /p>
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Renee\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 1550, in __call__
return self.func(*args)
File "C:\Users\Renee\AppData\Local\Programs\Python\Python35-32\tkinterguitest.py", line 52, in onOpen
file.write(im)
TypeError: write() argument must be str, not Image
Подробнее здесь: https://stackoverflow.com/questions/421 ... and-pil-in