import tkinter as tk
from tkinter import filedialog
from PIL import Image, ImageTk
def show_image(path):
img = Image.open(path).resize((300, 300))
img_tk = ImageTk.PhotoImage(img)
image_label.configure(image=img_tk)
image_label.image = img_tk
def open_file():
file_path = filedialog.askopenfilename()
if file_path:
show_image(file_path)
root = tk.Tk()
root.title("画像表示")
root.geometry("400x350")
btn = tk.Button(root, text="画像を開く", command=open_file)
image_label = tk.Label(root)
btn.pack()
image_label.pack()
root.mainloop()