Guest User

img_select

a guest
Feb 4th, 2024
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. import logging
  2. from pathlib import Path
  3. from tkinter import Tk, filedialog
  4. from typing import Optional
  5. def select() -> Optional[Path]:
  6.     r = Tk()
  7.     r.withdraw()
  8.     fp = filedialog.askopenfilename(
  9.         parent=r,
  10.         filetypes=[("Image files", "*.jpg *.jpeg *.png *.gif *.bmp")],
  11.         defaultextension=".jpg",
  12.         title="Select an image",
  13.         initialdir=".",
  14.     )
  15.     if not fp:
  16.         logging.info("No image selected")
  17.         return None
  18.     logging.debug(fp)
  19.     return Path(fp)
Advertisement
Add Comment
Please, Sign In to add comment