save canvas image in tkinter(python) postscript function



Python
library
pip

MeCab

numpy
digitize

mgrid

pad

polyfit

prod

shape

matplotlib
figure

pcolormesh

scatter

pytorch
BCELoss, MSELoss

device

Embedding

TensorDataset, Dataloader

RNN, LSTM
scikit-learn
SVC

scipy
interpolate
tkinter
postscript

image display

frame, grid

other
linear interpolation

OpenAI gym
CartPole-v0


Release date:2022/11/2         

In Japanese
<premise knowledge>
Python


■Description
Explain how to save the image displayed on canvas in tkinter.

■Example
Display a suitable image on canvas and save it. The extension of the image to be saved is ".ps", and tkinter cannot save in jpg, png. The red "canvas.postscript" part below corresponds to the saving process.

import tkinter as tk
from PIL import Image, ImageTk

app = tk.Tk()
img = Image.open('test.jpg')

tk_img = ImageTk.PhotoImage(img)
img_width, img_height = img.size

canvas = tk.Canvas(app, width=img_width, height=img_height)      # Creating an image display area
canvas.pack()
canvas.create_image(0, 0 , anchor = tk.NW, image=tk_img)        # image display

canvas.postscript(file="test.ps", colormode='color') # Save image

app.mainloop()










List of related articles



Python
library
pip

MeCab

numpy
digitize

mgrid

pad

polyfit

prod

shape

matplotlib
figure

pcolormesh

scatter

pytorch
BCELoss, MSELoss

device

Embedding

TensorDataset, Dataloader

RNN, LSTM
scikit-learn
SVC

scipy
interpolate
tkinter
postscript

image display

frame, grid

other
linear interpolation

OpenAI gym
CartPole-v0