forked from Rustam-Z/python-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.py
More file actions
22 lines (15 loc) Β· 693 Bytes
/
Copy pathfile.py
File metadata and controls
22 lines (15 loc) Β· 693 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Open Files Dialog Box
# By RΞ¨ST-4M π
# EightSoft Academy
from tkinter import *
from tkinter import filedialog
from PIL import ImageTk, Image
root = Tk()
def open():
global my_image # we always need global to open an image
root.filename = filedialog.askopenfilename(initialdir="examples/photos", title="Select a File", filetypes=(("png files", "*.png"), ("jpg files", "*.jpg")))
my_label = Label(root, text=root.filename).pack() # it returns the location of file as string
my_image = ImageTk.PhotoImage(Image.open(root.filename))
my_image_label = Label(root, image=my_image).pack()
my_btn = Button(root, text="Open file", command=open).pack()
mainloop()