I have a Python (2.7.16) program with a function that aims to:
- select a jpg file (via openfilename dialogue)
- save that file to a new file name
- close the file I have just created
Outside the function, I then try to open the saved file, but I get a "file not found" error. What am I doing wrong?
from tkinter import *
from PIL import Image as PIM
from tkinter.filedialog import askopenfilename
#Create a window
win= Tk()
win.geometry("1000x900+50+50")
win.title(" Display Images")
# Function to select and save an jpg image
def get_img():
imgin=askopenfilename(initialdir='/home/pi/Python',title='Choose Image File',filetypes=[('Image files', '.jpg')])
if imgin:
img1 = PIM.open(imgin)
img1.save("/home/pi/Python/thumb1.jpg")
img1.close()
# Create a Label widget to hold the image
label= Label(win)
label.grid(row = 0, column = 0, columnspan = 2)
get_img()
label.configure(image = "/home/pi/Python/thumb1.jpg")
label.update()
win.mainloop()