Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from PIL import ImageTk, Image
- from tkinter import filedialog
- # Initialize the window
- window = tk.Tk()
- window.title("Image Viewer")
- # Function to open an image file
- def open_image():
- file_path = filedialog.askopenfilename(filetypes=[("Image Files", "*.jpg;*.jpeg;*.png;*.gif")])
- if file_path:
- image = Image.open(file_path)
- image.thumbnail((400, 400))
- photo = ImageTk.PhotoImage(image)
- image_label.configure(image=photo)
- image_label.image = photo
- # Create a button to open an image file
- open_button = tk.Button(window, text="Open Image", command=open_image)
- open_button.pack()
- # Create a label to display the image
- image_label = tk.Label(window)
- image_label.pack()
- window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement