Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. import os
  2. import numpy as np
  3. import cv2
  4. from PIL import ImageTk
  5. import PIL.Image
  6. import msvcrt as m
  7.  
  8. from tkinter import *
  9.  
  10. path = 'img/'
  11. images = os.listdir(path)
  12. imgNum = len(images)
  13. idx = 0
  14.  
  15. def leftKey(event):
  16.  
  17.  
  18. changeImg()
  19. os.rename(path + images[idx-1], path + 'left/' + images[idx-1])
  20.  
  21.  
  22.  
  23. def rightKey(event):
  24. changeImg()
  25. os.rename(path + images[idx-1], path + 'right/' + images[idx-1])
  26.  
  27.  
  28.  
  29. def changeImg():
  30. global idx
  31. idx += 1
  32. if(idx == imgNum):
  33. root.destroy()
  34. else:
  35. img2 = ImageTk.PhotoImage(PIL.Image.open(path + images[idx]))
  36. panel.configure(image=img2)
  37. panel.image = img2
  38.  
  39.  
  40.  
  41. if not os.path.exists(path + 'left'):
  42. os.makedirs(path + 'left')
  43.  
  44. if not os.path.exists(path + 'right'):
  45. os.makedirs(path + 'right')
  46.  
  47. root = Tk()
  48. img = ImageTk.PhotoImage(PIL.Image.open(path + images[idx]))
  49. panel = Label(root, image = img)
  50. panel.pack(side = "bottom", fill = "both", expand = "yes")
  51.  
  52.  
  53. root.bind('<Left>', leftKey)
  54. root.bind('<Right>', rightKey)
  55. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement