-1

Guys I wanted to know how to save a png file to a specific path through tkinter I have a button and when I click in it I want it to save a specific png file in a path that I write in the entry u can look at my code here

from tkinter import *
from tkinter import filedialog
from tkinter import*
from tkinter.ttk import *
import pyautogui
from PIL import ImageTk,Image
import time
import os.path
def callback(event):
    w1 = e1.get()
    h1 = e2.get()
    im = pyautogui.screenshot('my_screenshot.png',region=(0,0, w1, h1))
    tru()
def save():
    save_path =e3.get()
    #if name_of_file is True:
    #name_of_file=name_of_file+1
    completeName = os.path.join(save_path, "my_screenshot.png")
window = tkinter.Tk()
window.wm_iconbitmap('Scissors-black.ico')
window.title("Screenshot Taker")
#window.geometry("500x500")
frame = LabelFrame(window,text="The Screenshot")
frame.grid(row=4,column=None)
e1 = Entry(window)
e2 = Entry(window)
l1=Label(window,text="Width")
l2=Label(window,text="Height")
l1.grid(row=0,column=0, pady = 2)
l2.grid(row=1,column=0, pady = 2)
e1.grid(row = 0, column = 1, pady = 2)
e2.grid(row = 1, column = 1, pady = 2)
b1 = Button(text="Save",command=save)
b1.grid(row=3, column=0, pady = 2)
e3 = Entry(window)
e3.grid(row =3, column=1, pady = 2)
L=window.bind("<Return>",callback)
def tru():
    my_img = ImageTk.PhotoImage(Image.open("my_screenshot.png"))
    l3=Label(frame,image=my_img)
    l3.grid(row=4,column=None)
    window.mainloop()


#label = tkinter.Label(window,text = "Press Enter to take a screenshot").pack()
  • 1
    Read [Tkinter understanding mainloop](https://stackoverflow.com/a/29158947/7414759) – stovfl Apr 19 '20 at 20:44
  • Since you have already taken the screen shot to an image file using `pyautogui`, you can just move the image file to the destination directory in `save()` function. Or directly save the image to the destination directory in `callback()` function. – acw1668 Apr 20 '20 at 01:02

1 Answers1

0

You can save image by Image module from PIL library

#import image module
from PIL import Image
#Create image object
image = Image.open(r"path_to_image")#type the path
image.save("Example.png") #type the location to be saved
Barel elbaz
  • 426
  • 3
  • 8