Guest User

Untitled

a guest
Jul 16th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. import tkinter as tk
  2. from PIL import Image, ImageTk
  3. import sys
  4. import os
  5.  
  6. name = os.path.basename(sys.argv[0])
  7. path = ""
  8.  
  9. try:
  10. path = os.path.normpath(sys.argv[1])
  11. except IndexError:
  12. print(f"Usage: {name} uri")
  13. sys.exit()
  14.  
  15.  
  16. window = tk.Tk()
  17.  
  18. # open the image from disk
  19. image = Image.open(path)
  20. width, height = image.size
  21.  
  22. ws = window.winfo_screenwidth()
  23. hs = window.winfo_screenheight()
  24.  
  25. x = (ws/2) - (width/2)
  26. y = (hs/2) - (height/2)
  27.  
  28. # create a Tk image and pack it
  29. img = ImageTk.PhotoImage(Image.open(path))
  30. panel = tk.Label(window, image = img)
  31. panel.pack(side = "bottom", fill = "both", expand = "yes")
  32.  
  33. # set the window details
  34. window.title("Kite - " + path)
  35. window.geometry(f"{width}x{height}+{int(x)}+{int(y)}")
  36.  
  37. window.mainloop();
Add Comment
Please, Sign In to add comment